Scripting the Checkpoint Component

We’ve discussed how we want our checkpoint and respawn to work and have created a basic trigger as a starting point. Now we’re going to create a Component to manage the trigger’s events as they’re raised:

1. Select the Checkpoint GameObject.

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

3. Name the script “CheckpointTrigger” 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 on the script to open it in the MonoDevelop-Unity IDE.

With the script in place, we can now tell the trigger how it should react to the player’s action. While there are three functions available to us, we’re only going to ...

Get Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.