Odd problem with a shootScript

I am making a car with a minigun turret on top, but i cant get my shoot script to work.
I wrote my own script but when that failed i copied and modified the one from the script-reference.

the code is:

var Bullet : Transform;

function Update () {
	if (Input.GetButtonDown("Fire1")) {
	
	var clone : Rigidbody;
	clone = Instantiate(Bullet, transform.position, transform.rotation);
	clone.velocity = transform.TransformDirection (Vector3.forward * 10000);
}
}

but i keep getting a error saying: Cant cast from source type to destination type

checked everywhere but other that restarting unity i cant find any other suggested solutions and i have already restarted 100 times or so… plz help :confused:

You declare the Bullet variable as a Transform and then you are trying to cast a rigidbody to it.

change

var clone:Rigidbody

to

var clone:Transform

Problem solved :slight_smile:

thx for the help :smile:

var Bullet : Transform;

function Update () {
	if (Input.GetButtonDown("Fire1")) {
		var clone : Transform;
		clone = Instantiate(Bullet, transform.position, transform.rotation);
		clone.rigidbody.velocity = transform.TransformDirection (Vector3.forward * 100);
	}
}