Setting up the schematic to randomly generate a jewel grid.
In this tutorial we’ll set up the schematic that creates our jewel grid and randomly fills it with jewels.
The grid’s size (rows and columns) will be defined by local start variables of the machine component playing the schematic. The grid’s actual height will be doubled, hiding the upper half of the grid – we’ll use this to achieve the effect of new jewels falling down from above.
First, we’ll set up the schematic to create the grid and fill it with random jewels.
Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.
We’ll set up local variables as Machine Start Variables 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.
Copy the previous start variable.
We need a prefab resource for handling our random jewels. Click on Add Prefab Resource to add a prefab resource.
We need 5 prefabs in this prefab resource, add the needed amount by clicking on Add Prefab.
Add Node > Value > Variable > Change Variables
We’ll use this node to store the doubled height (rows) of the grid.
Click on Add Variable to add a variable change.
Copy the previous variable change and change the following settings.
Add Node > Game Object > Grid > Create Grid
We’ll use this node to set up the grid that holds our jewels. The Grid nodes are a convenient way to create, manage and manipulate 2D and 3D grids of game objects.
Each grid is identified by it’s grid key.
The grid size defines the columns (X), rows (Y) and dimensions (Z) of the grid.
The X-Axis of the grid size defines the columns.
The Y-Axis of the grid size defines the rows.
The Z-Axis of the grid size is used to create multidimensional grids, for our match 3 game we only need a 2D grid, i.e. a Z size of 1.
The grid position defines where the grid’s root (and by this, the cell at X=0, Y=0, Z=0) will be placed in the game world.
The cell position defines the position offset between the cells of the grid.
Add Node > Game Object > Grid > Fill Grid Cells
We’ll use this node to fill our (currently empty) grid with random jewels (prefabs).
Add Node > Game Object > Grid > Hide Grid Cells
We’ll use this node to hide the upper half of the grid. The game objects assigned to hidden cells will be disabled – this helps us with our later added logic for finding matches.
This defines the area’s starting index in the grid.
We’ll use the local int variable rows as Y-Axis starting index, this makes sure we’re hiding the upper half of the grid.
This defines the area’s end index in the grid – all cells between the starting and end index will be used. Setting an axis to -1 will use the maximum index (i.e. the highest index) of the grid axis.
And that’s it for the schematic – click on Save Schematic and save it as GenerateLevel in Assets/Schematics/.
We’ll use an Auto Machine component to start our level generating schematic. Create a new game object in the scene (e.g. using the Unity menu: GameObject > Create Empty), rename it and move it out of the way.
Add an auto machine component to the game object (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.
And that’s it for now – don’t forget to save the scene.
Click on Play to test the game. You’ll see a randomly created grid of jewels and the HUD (displaying score and turns of 0).
The next tutorial will handle matching jewels.
© 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!