Game Development Reference
In-Depth Information
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
function OnBecameInvisible()
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.
Step 14. Create a new JavaScript file called spawn.js . Enter the code
shown in Listing 4.2 .
Search Nedrilad ::

Custom Search