Setting up the machines generating the level.
In this tutorial we’ll add the schematics we created in the previous tutorial using an Auto Machine and 3 Tagged Machine components.
First, create a new empty game object (e.g. using the Unity menu: Game Object > Create Empty), rename it to GameManager and place it at X=-5, Y=4, Z=0. We’ll be adding the machine components to this game object.
The BoardManager schematic handles generating the level – we’ll use an auto machine to do this at the start of the level.
Add an auto machine component to the GameManager (e.g. using the component menu: Makinom > Machines > Auto Machine) and change the following settings.
The Machine Start Variables we’ve set up in the schematic are automatically added here with their default values – since the default values are already what we need, we don’t have more to do here. Make sure all variables are enabled.
That’s it for the auto machine.
We’ll add 3 tagged machines for the random placement.
Add a tagged machine component to the GameManager (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.
Expand the Resource Overrides to change the used prefabs.
Click on Add Prefab multiple times – we’ll need 8 prefabs in total.
Click on Add Variable to add a start variable.
We’ll be adding between 5 and 9 walls to the level.
Copy the previous tagged machine by right clicking on the component’s name and selecting Copy Component. Add it by right clicking on the name again and selecting Paste Component As New.
Change the following settings.
We only need 2 prefabs this time, i.e. remove the not needed amount.
Change the random numbers – we’ll be adding between 1 and 5 food items to the level.
Again, copy the previous tagged machine by right clicking on the component’s name and selecting Copy Component. Add it by right clicking on the name again and selecting Paste Component As New.
The enemy objectCount will be set by the BoardManager that calls this tagged machine, so we don’t need local start variables this time.
And that’s it for now – don’t forget to save the scene.
Click on Play to test the game. The text message will be not yet be displayed (Day 1), since we haven’t set up the UI box prefabs yet, but after the screen faded in you’ll see the generated level – each time you start the game, different level will be generated.
The next tutorial will handle the player controls.
© 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!