Creating the Victory Trigger Script

Now that we have our constant values prepared, we can create a Component that tells our trigger how to end the level when the player enters it:

1. Select the triggerVictory GameObject.

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

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

4. Drag the triggerVictory GameObject to the _prefabs directory to save it as a Prefab.

5. In the Project Browser, select the newly created script and move it to the _scripts folder (or an appropriately named subfolder if you’ve been organizing!).

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

We’ll set up something relatively simple that waits briefly and then loads a provided ...

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.