Creating the boss encounters.

Chance Cornell
3 min readAug 26, 2021

Today, we will be creating our boss encounters that the player will face throughout the game. This was the final thing left to add to the game before build and release. I decided I wanted the game to continue until the player dies and kind of do a high score type of game. So I decided to scale up the difficulty of the game every five waves with a boss encounter.

First off, you will need your boss sprite and add the Rigidbody2D and Collider2D of your choice. Do our typical setup where the collider is a trigger and the gravity is set to zero. I added an animator and an audio source component as well to give the boss the same explosions that the enemies have.

I would also go ahead and create a new prefab for the laser formation the boss will be shooting.

We will now create a new script and call it ‘EnemyBoss’. We will go ahead and attach it to our prefab boss. The boss is pretty much the same as the enemies, but we are adding a health bar for the boss as well.

You will need to create a new UI Image for the health bar and position it where you like it. I have mine in the upper middle area and anchored there as well in case the resolution changes. You will need to add a slider component to the main health bar and set your ‘Max Value’ to whatever your boss’ max health will be. My boss has a max health value of 10. You will want the slider settings to have ‘Interactable’ turned off, ‘Transition’, and ‘Navigation’ set to ‘none’.

I also created another UI Image and made it a child of the first and renamed it as ‘FillArea’. I changed the color to red. Drag the ‘FillArea’ game object to the ‘FillRect’ field on the slider on the first UI Image you created.

Now in the ‘UIManager’ script, you will need to create a new variable for the slider we just created.

And now we will set the values for the slider based on health integers.

The final thing we have to do is in our ‘SpawnManager’ script we need to spawn the boss. We will do this in ‘Update’ and as I said before, I chose to spawn the boss every 5 waves until wave 20.

--

--