Shooter script

I am trying to do simple throwing of crates and seen this from tornado twins. Here is the script

var speed = 3.0; var
 cratePrefab:Transform;
 
 function Update ()  { 	
 // find out if a fire button is pressed
 	if(Input.GetButtonDown("Fire1")){
 		// create the prefab 		
 var crate = Instantiate(cratePrefab,transform.position,Quaternion.identity);
 		// add force to the prefab
 		crate.Rigidbody.AddForce(transform.forward * 2000);
 		 	} }

and it gets error : “Null Reference exception: Object Reference not set to an instance of an object.”

It doesn’t show anything still does the same thing. It is shooting it’s just shooting up along with the y axis and it’s shooting with an akward interval. Shoots one that doesn’t go normal and stops and when second is shot it pushes the first.

You’ve wrote crate.Rigidbody while the correct is crate.rigidbody (Rigidbody is a type). The correct form is:

      crate.rigidbody.AddForce(transform.forward * 2000);

Remeber also that your crate prefab must have a rigidbody for this to work.

aldonaletto - That did the trick. But in the tutorial I watched it was Rigidbody and it worked. It’s case sensitive? In the editor if I write it as Rigidbody it turns blue, if not it doesn’t turn any color.