Setting up some game mechanics.
In this tutorial we’ll set up walls that can be chopped down by the player, food that can be collected by the player and the exit that loads the next level.
First, we’ll set up the schematic to handle destroyable walls.
Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.
We’ll add an audio clip resource to play a random chopping sound effect.
Click on Add Audio Clip Resource to add an audio clip resource.
We need 2 audio clips, add the needed amount by clicking on Add Audio Clip.
Add Node > Animation > Mecanim > Play Mecanim Animation
This node plays a Mecanim animations or sets parameters. We’ll use it to play the chop animation of the player by setting the playerChop trigger parameter.
Click on Add Parameter to add an parameter that will be changed.
Add Node > Audio > Audio > Play Sound
We’ll use this node to play the chop sound with a random pitch.
Add Node > Base > Wait
This node waits for a defined amount of time. We’ll use it to wait for 0.1 seconds to give the animation/sound some time to play for a better visual result.
Add Node > Value > Variable > Change Variables
We’ll use this node to reduce the wall’s health by 1. The health will be stored in the object variable health on the wall. The damage done by the player is stored in a global variable.
Click on Add Variable to add a variable change.
Add Node > Value > Variable > Check Variables
We’ll use this node to check if the wall’s health reached 0.
Click on Add Variable to add a variable condition.
Add Node > Game Object > Game Object > Activate Object
This node is used to enable/disable game objects. We’ll use it to disable the wall when the health reached 0.
This node is connected to the Success slot of the Check Variables node.
That’s it for the schematic – click on Save Schematic and save it as Wall in Assets/Schematics/.
Now, we’ll set up object variables and a tagged machine handling the wall’s destruction on the wall prefabs. The following steps are the same for all prefabs (Wall1 to Wall8, you can find the prefabs at Assets/Tutorial Resources/Prefabs/).
You can e.g. set up the components on one prefab and copy them by right clicking on the name of the component and selecting Copy Component. Select the other wall prefabs and paste the component by right clicking on a component’s name and selecting Paste Component As New – this will paste the component on all selected prefabs.
First, we’ll add an Object Variables component to store the wall’s health. Add the component to the prefab (e.g. using the component menu: Makinom > Scenes > Object Variables) and change the following settings.
Click on Add Variable to add a variable to the object variables.
Now, we’ll add the Wall schematic with a tagged machine. Add the component to the prefab (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.
That’s it for the wall prefabs – since we’ve worked directly on the prefabs, we don’t need to apply the changes.
Next, we’ll set up the schematic to collect food.
We’ll set up a local variable as Machine Start Variable for easy setup in the machine component at a later time. When using the schematic in a machine component, the defined start variables will be added automatically, using their default values.
Click on Add Start Variable to add a local start variable that will be exposed to the machine component’s inspector.
We’ll add an audio clip resource to play a random consume sound effect – the actual audio clips will be added through resource overrides. Click on Add Audio Clip Resource to add an audio clip resource.
We’ll use this node to play the consume sound with a random pitch.
We’ll use this node to increase the player’s food by a local start variable foodChange. This will be set in the trigger machine starting this schematic.
That’s it for the schematic – click on Save Schematic and save it as Food in Assets/Schematics/.
The food will be collected when the player walks on it – i.e. we’ll use trigger machines to react to that. The setup is the same for both the Food and Soda prefab (found at Assets/Tutorial Resources/Prefabs/).
Add a trigger machine component to the prefab (e.g. using the component menu: Makinom > Machines > Trigger Machine) and change the following settings.
Expand the Resource Overrides to change the used audio clip.
We’ll need 2 audio clips, add them by clicking on Add Audio Clip.
The Machine Start Variables we’ve set up in the schematic are automatically added here with their default values, so all we need to do is adjust them to our needs. Make sure both variables are enabled.
That’s it for the food prefabs – since we’ve worked directly on the prefabs, we don’t need to apply the changes.
Next, we’ll create the schematic that handles loading the next level when the player reached the exit.
Add Node > Game > Game > Change Game State
We’ll use this node to stop the gameplay by inactivating the Game Running state.
Click on Add Game State to add a game state change.
We’ll use this node to wait for a second.
We’ll use this node to increase the level by 1.
Add Node > Game > Scene > Load Scene
This node is used to load a scene. We’ll use it to reload the current scene – which will start generating a new level.
We only want to fade out the screen, since our level generation will do the fade in for us. We’ll use a custom screen fade, overruling the default screen fade settings for scene changes (which are defined in Game > Game Settings).
That’s it for the schematic – click on Save Schematic and save it as Exit in Assets/Schematics/.
Finally, we’ll add the Exit schematic to the Exit prefab using a trigger machine. The prefab can be found at Assets/Tutorial Resources/Prefabs/.
And that’s it for now – since we’ve worked directly on the prefabs, we don’t need to apply the changes.
The next tutorial will handle the game manager and UI setup.
© 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!