Game Dev: How to shoot

Channel:
Subscribers:
1,060
Published on ● Video Link: https://www.youtube.com/watch?v=unn1JxXzAz0



Duration: 12:52
4 views
0


The 2nd part of this series, the 1st part is located here
https://youtu.be/ZiCMUGOE2k0

The only big mistake is I did not add the Firepoint.position into the first run which I corrected later in the video

Down below is the code however youtube does not like brackets

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Shooting : MonoBehaviour
{
public Transform Firepoint;
public GameObject BulletPrefab;

public float bulletForce = 10f;

// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
void Shoot()
{
GameObject Bullet = Instantiate(BulletPrefab, Firepoint.position, Quaternion.identity);
Rigidbody2D rb = Bullet.GetComponent (bracket go here) Rigidbody2D(bracket go here) ();
rb.AddForce(FirePoint.right * bulletForce, ForceMode2D.Impulse);
}







Tags:
Game
Gamedev
C++
Unity
Simple
MovementScript
MovinginUnity
GameDev
Dev
IndieGameDev
Visual
Visualstudios
simplemovementscripts
simple movement scripts
moving in c++
Transform
Transform.position
Game Dev
Game Devolpment
Shooting
bulletsinunity