Burst-fire enemy and zig-zag movement

Let’s go over the implementation of an enemy that shoots a burst of projectiles in all directions. I will also explain how to set the enemy movement to zig zag.

The base for the projectile was implemented in this article. I also added an additional projectile in this article.

Open up the Projectile script and ensure that space is set to Space.Self:

Add an empty game object to the Hierarchy and name it something suitable, such as Enemy_Burst.

Add one projectile as a child and then duplicate it eleven times. Increase the Z rotation by 30 for each projectile. Turn the game object into a prefab:

Now that the new projectile type has been made, let’s focus on the enemy. We will add a new zig-zag movement. Open up the Enemy script and add a function in which we will use a bit of math to create the zig-zag movement:

Add two float variables to the Enemy script and ensure they are serialised so that you can adjust on the Inspector:

Add another value to the EnemyType enum:

Add another case for the switch statement in the EnemyMovement function for the new enemy. Swap out the X movement for the new function and pass in the global variables:

Set the enemy type and add the projectile on the Inspector for the new enemy object:

Lastly, add the enemy to the spawn manager:

Good luck!

Unity / C# Game developer