quick method to destroy game objects by time

In some cases you’ll want to destroy a game object by time.

For this purpose you can use a little script like this one that you can attach to any object, as soon as you fill the lifeTime value in the editor, the gameObject will destroy itself within the given time.

 

public class destroyByTime : MonoBehaviour {
 
	public float lifeTime;
	// Use this for initialization
	void Start () {
		if(lifeTime != 0)
			Destroy(gameObject, lifeTime);
 
	}
 
}

Leave a Reply