2D Space Shooter: Creating Boss AI with Enum states

Every game needs a boss and creating a boss from scratch can be intimidating, but don’t worry. I will show you here how I created my boss for 2D Space Shooter.

Boss Wave incoming…

Creating the Boss AI

Boss Movement to a specific position

  1. We create the Enum States for our Boss. And set the state to START.
  • And we need a boolean to determine when we are in the _endPosition. So we create a boolean named _arrivedEndPosition;

Boss waiting Enum state

In Update, we check that if the state is BossState.WAITING
We start a Coroutine and give it an integer. Soon you see why.

How many seconds till our Boss moves

Boss Moving Enum state

Boss movement contains just a simple Move Right & Move Left

MoveRight Method
MoveLeft Method

Boss Vulnerable Enum state (Triple Coroutine)

Let’s make our Boss vulnerable for a while. This one has 3 different Coroutines.

How many seconds till Boss is vulnerable
Color change to Boss sprite
How many seconds till Boss isn’t vulnerable

From the beautiful snowy country with a touch of "good" humor? Inspired Unity Developer to learn more.