Setting up the enemy spawner.
In this tutorial we’ll create a schematic spawning enemies at a randomly selected spawn point in the scene. We’ll use the schematic in 3 Auto Machines to spawn the 3 different enemies repeatedly.
Enemy Spawner: Schematic
First, we’ll set up the schematic. Since the spawn points we’re going to use are game objects defined in the scene, we’ll use an actor for that.
Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.
Settings
We need an actor for the spawn points and a prefab resource for the enemy prefab.
Click on Add Actor to add an actor.
- Type
Select Game Object. - Find Object
Disable this setting.
We’ll add the used game objects of the actor in the machine’s inspector.
Click on Add Prefab Resource to add a prefab resource. The used prefab will be defined in the machine’s prefab using resource overrides.
- Name
Set to Enemy.
Spawn Prefab
Add > Game Object > Prefab > Spawn Prefab
This node is used to spawn a prefab. We’ll use it to spawn the enemy prefab at a randomly selected spawn point (actor).
- Prefab
Select Prefab 0: Enemy. - Target Type
Select Object.
Target Object
- Object
Select Actor 0: Scene Object. - Spawn At
Select Random.
And that’s it for the schematic – click on Save Schematic and save it as EnemySpawner in Assets/Schematics/.
Enemy Spawner: Auto Machine
Select the EnemySpawner game object in the scene hierarchy, we’ll add the enemy spawner schematic to it using an auto machine. The spawn points we’re going to use are child objects of this object.
Zombunny
Add an auto machine component to the game object (e.g. using the component menu: Makinom > Machines > Auto Machine). Change the following settings.
Start Settings
- Start
Enable this setting. - Repeat Execution
Enable this setting. - Repeat Delay (s)
Set to 3.
Machine Execution Settings
- Asset Type
Select Schematic. - Schematic Asset
Select EnemySpawner. - Execution Type
Select Single. - Update Type
Select Update.
Click on Add Actor Object multiple times to add 9 game object selection fields to Actor 0. Select SpawnPoint 1 to SpawnPoint 9 in the selection fields.
The game objects are child objects of the EnemySpawner game object.
Resource Overrides
Expand the Resource Overrides to change the used prefab.
- Override Prefabs
Enable this setting.
Click on Add Prefab to add a prefab that will be used.
- Prefab
Select Zombunny.
The prefab can be found at Assets/Tutorial Resources/Prefabs/.
Condition Settings
We’ll only want enemies to be spawned when the player is alive.
- Check Variables
Enable this setting.
Click on Add Variable to add a variable condition.
- Condition Type
Select Variable. - Variable Key
Set to health.
Use the Value string type. - Variable Origin
Select Object. - Game Object
Select Player. - Is Valid
Enable this setting. - Exists
Enable this setting. - Type
Select Int. - Check Type
Select Is Greater. - Check Value
Set to 0 (Value).
Zombear
Copy the previous auto machine component by right-clicking on it’s name and selecting Copy Component. Add the copy by right-clicking on the name again and selecting Paste As New Component.
Change the following settings in the new auto machine component.
Start Settings
- Repeat Delay (s)
Set to 5.
Resource Overrides
Expand the Resource Overrides to change the used prefab.
- Prefab
Select ZomBear.
The prefab can be found at Assets/Tutorial Resources/Prefabs/.
Hellephant
Again, paste the copied component by right-clicking on the name and selecting Paste As New Component.
Change the following settings in the new auto machine component.
Start Settings
- Start Delay (s)
Set to 5. - Repeat Delay (s)
Set to 30.
Machine Execution Settings
Remove 5 of the added Actor 0 game objects and select HSpawnPoint 1 to HSpawnPoint 4 instead of the currently selected game objects.
The game objects are child objects of the EnemySpawner game object.
Resource Overrides
Expand the Resource Overrides to change the used prefab.
- Prefab
Select Hellephant.
The prefab can be found at Assets/Tutorial Resources/Prefabs/.
And that’s it – don’t forget to save the scene.
Testing
Click on Play to start the game. The enemies will now spawn randomly at the spawn points, hunt the player and attack him.
This concludes the survival shooter game tutorial series for now. You can add additional content to the game, e.g. new levels and enemies or power ups (e.g. increasing the player’s damage or decreasing the fire timeout).