Attempting to create a top down shooter where the player can shoot zombies that spawn. I’m having trouble getting the projectiles to work, however. I’m new to unity so bear with me.
public Rigidbody projectile;
if (Input.GetMouseButtonDown(0))
{
if (bulletCount > 0) {
anim.Play (“Strike”);
ammo -= 1;
Rigidbody bullet = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
Physics.IgnoreCollision(bullet.collider, collider);
bullet.velocity = transform.TransformDirection(new Vector3(0, 0, bulletSpeed));
}
}
This is the player’s function that creates the bullet.
public class bullet : MonoBehaviour {
public void OnTriggerEnter(Collider c) {
Debug.Log("zombie died");
GameObject.FindGameObjectWithTag("Player").GetComponent<Tom>().decreaseMobCount();
Destroy(c.gameObject);
Destroy(this.gameObject);
}
}
This is the bullet’s function. Whenever I click in game, it tells me there is a nullreference exception, object reference not set to an instance of an object. I don’t understand the issue here.