Objective: To add 2 coroutines that handle the common and rare spawning powerups.

It is time to now bring some balanced spawning to our existing common and rare powerups and we are going to complete this by simply using our existing SpawnPowerupsRoutine() coroutine from within the “SpawnManager” script. There is no changes to where this coroutine is getting called (from within the SpawningEnemiesRoutine() coroutine in the “SpawnManager” script):

Objective: Part 02 of implementing a 5 wave spawn system that spawns an increasing number of enemies with each wave.

Creating a Modular Coroutine for Enemy & Powerup Wave Spawning

Objective: To implement a 5 wave system that spawns an increasing number of enemies with each wave.

With just a few final features to be implemented before I can call this game finished, let’s take a look at building a spawn system that flows sequentially when one wave ends and the next starts. For this feature we aren’t going to use multiple scenes and instead take the current scene and use a modular coroutine to handle the spawning waves. Let’s get into it…

Creating Some Variables

Objective: To add a new firing method to our laser enemy, the laser beam!

Let’s now give our laser enemy a new and improved firing method besides the basic lasers that shoot down the screen. Let’s give the laser enemy a new giant laser beam! Let’s jump into it…

Adding Some Code to “LaserEnemyBehaviour” Script

Objective: To give the teleport enemy a shield that it spawns with.

Let’s now add a new feature to our teleport enemy which is going to be a shield that allows for 2 hits before it is able to be destroyed. Combined with the avoid shot (teleport feature) this is going to be quite a tricky enemy to kill! Let’s get into it…

Let’s Add the Shield to the Enemy

Let’s add the shield sprite to the ‘Teleport_Enemy’ prefab as a child. From here, we need to change the color of the sprite to Red (255, 0, 0, 255) and set the Sorting Layer to Foreground (2)

Objective: To give our enemy a detection mechanism that teleports them out of the way of the players lasers!

Now that we have setup some new movement for our teleport enemy, we are going to add in a new feature that uses raycasting to detect when a players laser is in front of it and then it will teleport out of harms way to a new position on the screen within set boundaries. There is also going to cooldown for this feature to make sure that we are actually able to destroy it! Let’s get into it…

Let’s Start With Some Code

We only need…

Objective: To give our newly created teleport enemy some different movement patterns!

This movement is going to have a mix of straight and angular movement depending on it’s spawn/respawn position and and it’s end position in which we will be using random Vector3 coordinates.

Let’s Create Some Code — Teleport Enemy

I have created a new script for this enemy called “TeleportEnemyBehaviour”.

Objective: To give our new laser enemy some new movement!

Let’s now setup some new movement for our last enemy to be implemented in the 2D Galaxy Shooter. As this enemy is going to have the laser beam feature, I decided the best movement for them would be smooth left to right whilst moving up and down(sine wave):

Objective: To create 2 new enemy types that are going to have different movement, weapons and avoidance features.

Firstly I have gone ahead and grabbed some 3D spaceship game objects to take a top down photo of to edit and save as a PNG file in Photoshop, exporting them out onto a sprite sheet. I now have 3 new models for 3 different types of enemies. The first enemies features that I have previously created will remain as is, but these 2 new ones are going to have some pretty cool features!

Enemy 1-Original

Objective: If an enemy gets too close to the player, they are going to try to “ram” them with increased speed!

We are going to add this feature to our original enemy type to spice them up a little bit. Luckily for us we some existing enemy raycasting code that we can try to tweak and make our lives a bit easier. Let’s get into it!

Within the “Enemy” Script

We only need to work within the “Enemy” scri pt for this one, so let’s open it up and get started:

Chris Hilton

Aspiring Unity Game Developer with a passion for bringing code to life!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store