I’m trying to create a basic FPS script that I thought I could handle, however I keep getting this error:
NullReferenceException: Object reference not set to an instance of an object
Fire.Shoot () (at Assets/Scripts/Fire.cs:24)
Fire.FixedUpdate () (at Assets/Scripts/Fire.cs:19)
The error pops up anytime I press the left mouse button in play mode.
Here is my shooting script called Fire:
using UnityEngine;
using System.Collections;
public class Fire : MonoBehaviour {
public GameObject bullet;
public GameObject shell;
public GameObject firePoint;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
if(Input.GetKeyDown(KeyCode.Mouse0)){
Shoot();
}
}
void Shoot () {
Instantiate(bullet,transform.position, transform.parent.rotation);
bullet.rigidbody.AddForce(bullet.transform.forward * 2000f);
}
}
I have no idea what this error means or how to fix it. Any help is appreciated.