Game Toolkit for Unity
Setting up the enemy machines.
In this tutorial we’ll set up the enemy game objects. We’ll add object variables and machine components using the schematics we created in the previous tutorial.
The setup for both enemies (enemy1 and enemy2) is the same (except for minimal differences). The following component setup can be repeated for both enemy prefabs, or you can just copy the components and paste them on the other enemy. The prefabs can be found at Assets/Tutorial Resources/Prefabs/.
First, we’ll set up the object variables of the enemies. Add an object variable component to the prefabs (e.g. using the component menu: Makinom > Scenes > Object Variables). Change the following settings.
Click on Add Variable to add an object variable. This variable will store if the enemy is facing left or right.
Click on Add Variable again to add another object variable. This variable will store the enemy’s health.
Copy the previous variable and change the following settings. This variable will store the points the player earns for killing this enemy.
Copy the previous variable and change the following settings. This variable will store the damage the enemy will deal to the player (will be handled in a later tutorial).
Click on Add Variable again to add another object variable. This variable will store the enemy’s speed.
That’s it for the object variables.
Next, we’ll add the Enemy schematic (handling the enemy’s movement) using a tick machine.
Add the component to the enemy prefabs (e.g. using the component menu: Makinom > Machines > Tick Machine). Change the following settings.
Now, we’ll add the Flip schematic using a tagged machine that will be stared by the tag flip. This will be called when the enemy changes direction.
Add a tagged machine component to the enemy prefabs (e.g. using the component menu: Makinom > Machines > Tagged Machine). Change the following settings.
Click on Add Starting Tag to add a tag that can start this machine.
Next, we’ll add the EnemyHit schematic (handling the enemy being hit by a rocket) using a tagged machine that will be stared by the tag rocketHit.
Expand the Resource Overrides to change the used sprite. Since enemy1 only has 1 health (i.e. dies on the first hit) we only need a damage sprite for enemy2.
Click on Add Sprite to add a sprite that will be used.
Finally, we’ll add the EnemyDeath schematic (handling the enemy’s death) using a tagged machine that will be stared by the tag die. This machine will later also be started through bombs.
Expand the Resource Overrides to change the used sprite.
And that’s it – we don’t need to apply the changes, since we’ve worked on the enemy prefabs directly.
If you want to test your enemies, just drag them into the scene and click on Play. The enemis will move and if you shoot them, they’ll die once their health is gone. They aren’t yet able to damage the player – we’ll do this later.
The next tutorial will handle enemy spawners.