O'Reilly logo

Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation by James A. Henley, Matthew Johnson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Scripting the Pit Trigger Component

Just as we did with the Checkpoint GameObject, we’re going to create a Component that tells our trigger what to do when the player enters it:

1. Select the Pit GameObject.

2. Click the Add Component button and choose New Script.

3. Name the script “PitTrigger” and ensure that the language is set to CSharp.

4. In the Project Browser, select the newly created script and move it to the _scripts folder.

5. Double-click the script to open it in MonoDevelop-Unity.

The script will be relatively simple. We’ll iterate through the level’s checkpoints to find the nearest one that the player has activated and immediately return the player to its location. If anything other than the player contacts the trigger volume, we’re ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required