I am trying to make a first person shooting game which my character shoots my bullet Prefab, however, it can’t shoot out anything when I press space bar and unity said it was a null reference Exception error. I don’t know what to do as a newbie and here below is my code and what should I do?
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
// rotate around y - axis
transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);
// Move forward / backward
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis("Vertical");
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitPrefab, GameObject.Find("spawnPoint").transform.position, Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward *2000);
}
}