Summary
The next step in developing John Lemon’s Haunted Jaunt is to create an end point to the game. This will enable you to create a complete experience for players, and develop your confidence writing code.
In this tutorial, you’ll:
- Use a UI (user interface) feature to create a game ending screen
- Create a GameEnding Trigger
- Write a custom game ending script
- Once you’ve completed this tutorial, you’ll have a complete level ready to populate with enemies to make the player’s task more difficult.
Set up the UI
You’ve already done a lot of work to set up the character, environment and camera for your game. Next you need to create an ending, so that the game actually finishes when JohnLemon escapes the house. Once you’ve done this, you’ll be ready to populate your game with enemies and make some final enhancements.
Before you begin to create anything, it’s important to know what you’re trying to achieve.
When JohnLemon reaches the exit the game should fade out and quit, but you need to be careful with this — quitting in the Unity Editor and quitting in the final built version of the game are different.
First, though, you need to make the game fade out. To do that, you’re going to use Unity’s UI (user interface) system.
1. In the Hierarchy window, click the Create button. This can be used to create all sorts of basic GameObjects.
2. Go to UI > Image. A UI Image can be stretched across the player’s entire screen, and it;s opacity can be changed to create a fade effect. Perfect!
This will add a few new GameObjects to your Scene:
3. In the Scene window, click the 2D button in the top bar to enable 2D Mode. This will enable you to see the new GameObjects properly.
4. In the Hierarchy, select the Canvas GameObject. Place your cursor over the Scene and press F.
5. Zoom in to look at the Canvas and Image more closely. You can either use the scroll wheel or press Alt, right click, and drag.
6. In the Hierarchy, select the EventSystem GameObject. This GameObject has components attached which work together to allow any UI elements on the screen to interact with user input. However, in your game the player doesn’t need to be able to interact with the UI.
7. Right click on the EventSystem GameObject and select Delete.
Next, you’ll use the two remaining GameObjects (Canvas and Image) to create the fade effect.