Setting up the pickup spawner.
In this tutorial we’ll create the schematic spawning pickups and set up the global machine playing the schematic.
Pickup Spawner: Schematic #
First, we’ll set up the schematic spawning the pickups.
Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.
Settings #
We’ll add the bomb crate and health crate as prefabs.
Prefabs #
Click on Add Prefab Resource to add a prefab resource.
- Name
Set to Health. - Prefab
Select healthCrate.
The prefab can be found at Assets/Tutorial Resources/Prefabs/Pickup/.
Click on Add Prefab Resource to add another prefab resource.
- Name
Set to Bomb. - Prefab
Select bombCrate.
The prefab can be found at Assets/Tutorial Resources/Prefabs/Pickup/.
Wait #
Add Node > Base > Wait
We’ll wait 5 seconds between pickup spawns.
- Time (s)
Set to 5 (Value).
Change Variables #
Add Node > Value > Variable > Change Variables
We’ll use this node to create a spawn position with a random X-axis.
Click on Add Variable to add a variable change.
- Change Type
Select Variable. - Variable Key
Set to position. - Variable Origin
Select Local. - Type
Select Vector3. - Operator
Select Set. - Vector3 Type
Select Value > Set Axis. - X-Axis
Select Value > Random and set the 1st field to -15 and the 2nd field to 15. - Y-Axis
Set to 15 (Value). - Z-Axis
Set to 1 (Value).
Variable Fork #
Add Node > Value > Variable > Variable Fork
We’ll use this node to check the player’s health – this will determine which pickup can be spawned.
If the player’s health is above 75, we’ll spawn a bomb. If the player’s health is below 25, we’ll spawn a health crate. In any other case, we’ll randomly spawn a bomb or health crate.
Variable Settings #
- Variable Key
Set to health. - Variable Origin
Select Object. - Object
Select Player.
Change the already added variable condition.
- Is Valid
Enable this setting. - Exists
Enable this setting. - Type
Select Int. - Check Type
Select Is Greater Equal. - Check Value
Set to 75 (Value).
Copy the variable condition.
- Check Type
Select Is Less Equal. - Check Value
Set to 25 (Value).
Random #
Add Node > Base > Random
This node is used to randomly play a next node. We’ll use it to randomly spawn a bomb or health crate in the next step.
This node is connected to the Failed slot of the Variable Fork node.
Click on Add Node to add a 2nd random slot – the node should now have 2 slots.
Spawn Prefab #
Add Node > Game Object > Prefab > Spawn Prefab
We’ll use this node to spawn a bomb crate.
This node is connected to slot 0 of the Variable Fork node (health is greather equal 75) and the Random 0 slot of the Random node.
- Prefab
Select Prefab 1: Bomb. - Target Type
Select Position.
Position #
- Vector3 Type
Select Vector3 Variable. - Variable Key
Set to position. - Variable Origin
Select Local.
Spawn Prefab #
Add Node > Game Object > Prefab > Spawn Prefab
We’ll use this node to spawn a health crate, copy the previous node and change the following settings.
This node is connected to slot 1 of the Variable Fork node (health is less equal 25) and the Random 1 slot of the Random node.
- Prefab
Select Prefab 0: Health.
That’s it for the schematic – click on Save Schematic and save it as PickupSpawner in Assets/Schematics/.
Pickup Spawner: Global Machine #
Now we’ll set up the global machine handling our pickup spawning. You can learn more about them in the global machines documentation.
Navigate to Base/Control > Global Machines and change the settings of the first global machine (Default). We’ve already used that global machine in our health pickup and bomb schematics.
Machine Execution Settings #
- Name
Set to Pickup Spawner. - Schematic Asset
Select PickupSpawner. - Execution Type
Select Single. - Update Type
Select Update.
Execution Settings #
The pickup spawner should automatically start when the level was loaded to spawn the first pickup.
- Global Machine Type
Select Scene.
That’s it for the global machine – click on Save Settings to save the changes.
Updating the Game Starter #
We need to do one more thing – because the global machine will only start when loading a level, it wont start when we play the scene in the editor (because that wont load the level, only after the player died this mechanic kicks in, as we reload it in that case). We’ll use the PickupSpawner schematic as a start schematic in the Game Starter.
Select the Game Starter game object in the scene hierarchy and change the following settings in the inspector.
- Start Schematic Asset
Select PickupSpawner.
And that’s it – don’t forget to save the scene.
Testing #
Click on Play to start the game. Pickups will now be spawned after 5 seconds in the game. After a bomb exploded or a health crate was collected, the next pickup will be spawned after another 5 seconds.
The next tutorial will handle the UI setup.