I was trying to make an automatic gun and followed this helpful answer. But then I got this error! Here is my script and error:
//Here are the relevant variables!
private var lastShot;
var shotInterval : float = .1;
var MPS : int = 35;
var BB : Rigidbody;
...
// Here is the part of the script that gets the error
if(Input.GetMouseButton(0)){
if(Time.time - lastShot >= shotInterval){
Instantiate(BB, transform.position, transform.rotation);
BB.velocity = transform.TransformDirection(Vector3( 0, 0, MPS ));
lastShot = Time.time;
}
}
Here is the Error:
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs)
Shoot.Update () (at Assets/Scripts/Shoot.js:20)
What can I do to fix the error?
“Help! I need somebody! Help! Not just anybody!..”