So I was watching the Brackey’s tutorial on Prefab shooting, and I wrote down the script:
function Update () {
var bullet : Rigidbody;
var Speed = 20;
if (Input.GetMouseButtonDown(0))
{
var clone = Instantiate(bullet, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3 (0, 0, Speed));
Destroy (clone.gameObject, 3.0);
}
the variables “bullet” and “speed” aren’t showing up in the inspector window in Unity. The game won’t work unless I drag the gameobject (the bullet) into the rigidbody slot. Do I need to do a GetComponent.; in function Start ()? Will that work better?