Game Toolkit for Unity
Setting up the game over mechanic.
In this tutorial we’ll create a schematic to check the player’s food and end the game if the food is gone. Game over will display a message and restart the game.
First, we’ll create the schematic to check and handle game over.
Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.
Add Node > Value > Variable > Check Variables
We’ll use this node to check if the player’s food is gone.
Click on Add Variable to add a variable condition.
Add Node > Game > Game > Change Game State
We’ll use this node to start stop the game from running.
This node is connected to the Success slot of the previous node.
Click on Add Game State to add a game state change.
Add Node > Audio > Audio > Play Sound
We’ll use this node to play a death sound.
Add Node > UI > Fade Screen
Now it’s time to fade out the screen.
Add Node > UI > Dialogue > Show Dialogue
This node is used to show a dialogue. We’ll use it to display the current day (level).
Add Node > Value > Variable > Change Variables
We’ll use this node to reset the level to 1 and the food to 100.
Click on Add Variable to add a variable change.
Copy the previous variable and change the following settings.
Add Node > Game > Scene > Load Scene
We’ll use this node to reload the current scene – which will start generating a new level.
Since the screen is already faded out and we don’t want to fade in (handled by the level generator), we’ll use a custom screen fade setup.
That’s it for the schematic – click on Save Schematic and save it as CheckGameOver in Assets/Schematics/.
Finally, we’ll add the game over mechanic to the Player game object in the scene using a tagged machine. The machine will be started by enemy attacks and consuming food per turn.
Add a tagged machine component to the player (e.g. using the component menu: Makinom > Machines > Tagged Machine) and change the following settings.
Click on Add Starting Tag to add a tag that can start this machine.
And that’s it – apply the changes to the player’s prefab by clicking on Overrides > Apply All (top of the inspector).
Don’t forget to save the scene.
Click on Play to test the game. You’ll now be able to die when running out of food.
This concludes the 2D roguelike game tutorial series. You can add additional content to the game, e.g. bigger levels (setting columns and rows in the machine starting the BoardManager schematic) or power ups for the player to chop through walls faster (changing the global variable wallDamage).
© 2015 Gaming is Love e.U.
Disclosure: This site may contain affiliate links, which means I may receive a commission if you click a link and purchase something that I have recommended. While clicking these links won’t cost you any money, they will help me fund my development projects while recommending great assets!