Hey, im having this weird error. I have no idea why, im doing everything good in the inspector, im using particles. Im doing muzzle flash, here’s the script. Thank you for helping:))
ERROR: NullReferenceException: Object reference not set to an instance of an object
I would suggest you to ignore this
This is the error
using System.Collections;
public class Shootings : MonoBehaviour {
public GameObject bulletPrefab;
public Transform Spawn;
public bool ImFacingLeft;
public Transform muzzelFlash;
void Start ()
{
}
void Update ()
{
if (Input.GetButtonDown(“Fire1”))
{
GameObject muzzle = Instantiate(muzzelFlash, Spawn.position, Spawn.transform.rotation) as GameObject;
muzzle.transform.parent = Spawn.transform;
}
if(Input.GetKeyDown(KeyCode.A))
{
ImFacingLeft = true;
}
if(Input.GetKeyDown(KeyCode.D))
{
ImFacingLeft = false;
}
if (Input.GetButtonDown(“Fire1”))
{
FireBullet();
}
}
void FireBullet(){
//Clone of the bullet
GameObject Clone;
Clone = Instantiate(bulletPrefab, Spawn.position,Spawn.transform.rotation) as GameObject;
if(ImFacingLeft == false)
{
Clone.rigidbody2D.AddForce(Vector2.right * 50);
}
if(ImFacingLeft == true)
{
Clone.rigidbody2D.AddForce(Vector2.right * -50); }
}
}