Game Development Reference
Fig 4.3 Adding a cube with a large box collider to the scene.
Listing 4.1 Code to Destroy an Object When It Moves out
of the Camera's View
Step 13. Attach destroyWhenGone to the ball prefab. This code will destroy
the object when it goes outside the area visible on the screen—the reason
being that soon we will create code to spawn balls continually. When
balls move outside the screen, they will be outside the game play area.
In this case, they are no longer needed; instead of the physics system
processing their location constantly and the game engine performing
any other behaviors with them, it makes more sense to just get rid
of them completely.
shown in Listing 4.2 .