Destroying Bullets after 'x' amount of time

OK so i did this in my uni class the other day but have lost the code and cant remember exactly what i did…

Anyway i have bullets that are shooting fine, all i want to do is make it so they disappear after 8 seconds. I’ve instantiated the bullets and created an array for them, but cant figure out for the life of me how i destroyed the bullets in the array last time.

This is my code so far…

#pragma strict

var newBullet : Rigidbody;
var bulletSpeed : int = 5;
var bulletArray : Array = Array();
 
function Start () {

}

function Update () {

	if (Input.GetMouseButtonDown(0))
	{
		Debug.Log ("Left click detected");
		
		var latestBullet = Instantiate (newBullet, this.transform.position, this.transform.rotation);
		bulletArray.Add(latestBullet);
		
		latestBullet.AddRelativeForce(0,0,bulletSpeed);
	}
}

I have tryed Destroy(newBullet, 8) and also Destroy(newBullet.gameObject, 8) as i have scoured the forums to find this to be a common fix for people, however for me it just keeps showing an error message that says ‘Destrying assets is not permitted to avoid data loss’… it might be worth pointing out my bullet is a rigidbody also.

Any help would be appreciated thanks :slight_smile:

Never mind, ive solved it… i was referencing the wrong variable in Destroy(gameObject). I referenced newBullet instead of latestBullet

Solved!