Maschine Gun Script

Hi :slight_smile:

I just want that my maschine gun could shoot, but it doesn’t works… :frowning: what is wrong? (sorry for my bad english, i am from Germany)
Here it is:

public var bulletPrefab : Transform;
public var bulletSpeed : float = 6000;

function Update() {
if (Input.GetButtonDown(“Fire1”)) {
if (!bulletPrefab || !bulletSpeed) {
Debug.Log("[Shoot] ‘bulletPrefab’ or ‘bulletSpeed’ is undefined’);
} else {
var bulletCreate = Instantiate(bulletPrefab, GameObject.Find("SpawnPoint’).transform.position,Quaternion.identity);
bulletCreate.rigidbody.AddForce(transform.forward * bulletSpeed);
}
}
}

I think… the problem is that your bulletPrefab is set to a transform, as opposed to a gameObject. You also have an extra space in Quaternion ion down near the body.

Pst: Next time use tags to make your code easier to read.