This article will be the final one for the space shooter project and I will deal with the creation of the last enemy wave here. This wave will only have one enemy, which is a boss that combines several features from the previous articles.

For the boss I created a brand new script called BossAI.
Open up the script and add these variables:
- A float for the speed that the boss moves into the scene with
- An int for the score the player receives when the boss has been destroyed
- A GameObject array for the three types of projectiles the boss has
- A GameObject for the explosion effect to show when the enemy has been defeated
- Three separate Transform arrays for the different positions at which the projectiles will get instantiated
- Three floats to control the shooting cooldown
- An int for the amount of hits the boss can take
- A bool to check if the boss is dead
- A Transform to use for keeping the hierarchy tidy
- A Transform to reference the player
- An AudioManager to play the sound effects
- And lastly, an UIManager, which will be used for showing the victory text.

Create the boss object and add eight empty game objects for the different positions to instantiate the projectiles:

Add all the empty game objects to the script as well as the explosion effect:

As this object is large and does not have a completely square or round shape, I used a polygon collider to match the shape more accurately:

Also add the three types of projectiles. You can follow this article to create a standard projectile. The large projectile is made in the same way as article one demonstrates. In order to create a burst projectile, please follow this article:

Back to the script. Initialise projectile parent, player Transform, UIManager and the AudioManager in the Start function:

Add a function which will move the boss to the middle of the screen and then stop:

Set up an enum to make it easy to see which projectile should be used:

Add a function for standard shooting which will take in a Transform for the position and an int for the projectile type:

Add another function for the burst which will randomly select position to instantiate the projectile:

In the last shoot function boss will aim at the player before shooting. The instantiation position will depend on which side of the boss the player is:

Add a coroutine which will get called when the boss has been hit by a laser, and will change colour for a brief moment to show that the boss was hurt:

Add another coroutine which will instantiate the explosion effects when the boss has been defeated. I used all the fire point positions here to instantiate the explosion. At the end of the routine we will show the winning text by passing in the value of 100 to the UIManager:

Add the OnTrigger2D function to detect the player object and the laser:

Lastly, in the Update function add two raycasts to detect, if the player is in front of the boss and if so, shoot. We will also call the three functions here: ShootBurst, ShootTowardsPlayer and BossMovement:

Final result:

Unity / C# Game developer