Adding relative force to a bullet

Hi,

Recently started using unity and I’m having a problem adding relative force to a bullet. The position the bullet spawns at is just in front on the player controller, however I can’t make it shoot forward it just spawns and lands on the floor. Any help would be appreciated.

#pragma strict

var bullet : Rigidbody;
var bulletSpeed : int = 100;

function Start () {

}

function Update () {

if (Input.GetMouseButtonDown(0))
{
	Debug.Log ("Left click detected");
	Instantiate (bullet, this.transform.position, Quaternion.identity);
	bullet.AddRelativeForce(Vector3.forward * bulletSpeed);
}

}

You must reference the instantiated object and not the prefab. Like this:

if (Input.GetMouseButtonDown(0))
{
     Debug.Log ("Left click detected");
     GameObject bullet = (GameObject)Instantiate (bulletPrefab, this.transform.position, Quaternion.identity);
     bullet.GetComponent<RigidBody>().AddRelativeForce(Vector3.forward * bulletSpeed); 
}

Note that when you use Vector3.forward, it will always go along the in the direction of the +Z world axis. If you wan’t to make it go in its own forward direction, you use bullet.transform.forward.