We finish this chapter with some more useful techniques.
What if, at one point, the user reaches the edge of the terrain or world you created and falls off? Instead of expecting the user to quit and restart, you should solve the problem elegantly. We place a large, invisible plane underneath our world, as a trigger to reset the player.
Add a Plane GameObject and set its
Mesh Collider
to Is Trigger. Make it large enough to extend to all sides of the scene and move it down underneath all other objects, as in the setup in the next screenshot.Disable its Mesh Renderer, to make it invisible.
Create a new C# script called
resetPlayer
and add the following code. It takes three private variables: one for the player's position (pos
), one for its rotation (rot
), and then the actual reference to the player (thePlayer
). This is shown in the following code:using UnityEngine; using System.Collections; public class resetPlayer : MonoBehaviour { private Vector3 pos...