The parts that aren’t working are the yield and destroy commands, everything else works perfectly without those two lines of code. How can I get the bullets to de-spawn after a given amount of time. Thanks.
#pragma strict
var bullet : GameObject;
var distance = 10.0;
function Update () {
if (Input.GetMouseButtonDown(0)) {
var mousePosition = Vector3(Input.mousePosition.x, Input.mousePosition.y, distance);
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
var shoot = Instantiate(bullet, transform.position + new Vector3 (.7, 0, 0) , Quaternion.identity) as GameObject;
shoot.transform.LookAt(mousePosition);
shoot.GetComponent.<Rigidbody2D>().AddForce(shoot.transform.forward * 500);
yield WaitForSeconds (3);
Destroy(gameObject);
}
}