May 2018
Beginner
492 pages
11h 53m
English
Another strategy for managing object life cycle is to limit their duration. This is especially effective for things like projectiles (bullets, arrows, bouncyballs) or other objects that the player cares about most when its instantiated and then isn't paying attention to as gameplay moves on.
To implement, you could put a timer on the object prefab itself to destroy itself when time runs out.
Modify the DestroyBall.cs script to destroy the object after delay seconds:
public float timer = 15f;
void Start () {
Destroy (gameObject, timer);
}
When you play, notice that the ground plane remains substantially less crowded than before. Each BouncyBall will be destroyed after 15 seconds or when it has fallen off the plane, ...
Read now
Unlock full access