Missing a variable assignment

Hello,

I am working on a top down shooter for practice project. The project has one scene, “Testy” that has a plane named “Floor”; a cube named “Ship”; a small cube named “Bullet”; Lights and a camera. Bullet has a rigidbody. Ship has a rigidbody, a movement and shoot script and a camera child. I am having trouble with the shoot script.

#pragma strict
//A java script to shoot a bullet from the ship
function Start () {

}
//Here Unity says the Bullet variable is undefined 
var Bullet : Transform;

function Update ()
//This should generate a bullet at the middle of the ship object
{
    if(Input.GetKeyDown(KeyCode.Mouse0))
    {
    Instantiate(Bullet,transform.position,Quaternion.identity);

    Bullet.rigidbody.AddForce(transform.forward * 1000);
    }    
}

With a search of google and youtube I can’t seem to find a way to fix this.

In your inspector, drag a Bullet onto the slot below your script name for the bullet. I suggest making Bullet a prefab. This won’t instantiate the Bullet variable (BTW - it’s customary usually to use lower case to start variable names), but it’ll create a new instance of a Bullet which you should assign to a variable. You can then add the rigid body to what you’ve created. For example:

var bulletInstance = Instantiate(bullet,transform.position,Quaternion.identity);
bulletInstance.rigidbody.AddForce(transform.forward * 1000);

Yep. Thank you goat and thank you unity for the simple solutions. kicks self