Journal 47 — Make a Boss Level in Unity Space Shooter

Chris Nielsen
6 min readJul 1, 2021

--

The final challenge in this series is to add a boss level for the end of the game.

My approach to this was the following:

  1. Create new boss artwork, but use what’s already available to help speed things up.
  2. Add hit zones and visuals to show damage to parts of the boss.
  3. Have the boss move on a waypoint system to keep it on screen.
  4. Update the UI to show a game winning screen and ability to restart.

The first part of this challenge is to take some of the artwork and reuse and modify. Any part of the artwork can eventually be changed out at a later time if you have more time. To make this easy, I used the basic enemy ship but increased the scale.

Unity, increased scale of basic enemy to make a Boss

I used GIMP and added some layered paint marks to illustrate gashes / cracks in the boss ship on different areas.

GIMP, add damage layers and export PNG files to Unity

To show the damage in stages, I used the boss game object and added some hit zones and damage areas that would emit particle effects.

Unity Boss gameobject organization, hit zones and particle effects

The damage visuals combined with particle effects in Unity would indicate the damage stages.

Unity damage effects on Boss while in Playmode

The boss C# script inherits some of the enemy base class behaviors, but has its own waypoint movement, lasers, and control for the hit boxes and particle system emissions for the damage stages.

This first part of the script contains the variables for the particle systems and box colliders for the damage zones.

To show the visuals, I used the animator, which I will explain more later.

Unity C# script for Boss, variables

The following part of the script continues with more variables: bool variables to check the stage of damage, a hit count variable to count the hits on each trigger, a variable for the Spawn Manager, and the boss speed.

In the Start method, we get references to the hit colliders.

Unity C# script for Boss, variables and Start method

We continue with references to the damage particle systems, set all particle systems off, and set the first hit area enabled. We get a reference to the animator, a reference to the Spawn Manager, set the first stage function, and assign the waypoint path from the Game Manager.

Unity C# script for Boss, Start method (cont’d)

In the last part of the boss Start method, we get a reference to the UI Manager, and we set the first animation which contains a single sprite that shows the base enemy image.

The Update method is similar to the other enemies. I modified the laser firing slightly to add a bool check if the Spawn Manager stop spawning is still false.

Unity C# script for Boss, Start method and Update method

The next series of screenshots show the rest of the boss script with public methods for each stage start and for each stage that is over. We have a hit counter reset for each stage, and once the stage is over, we change the animation and show a new sprite with an increased level of damage, and we play the associated particle system.

Unity C# script for Boss, waypoint movement in Update, and Boss Stage functions
Unity C# script for Boss, Boss Stage functions (cont’d)
Unity Boss gameobject in Inspector, all components and references

Regarding the ship visuals described above, I created an animation clip for each stage of damage, but instead of a series of sprites, I added a single sprite and the clip just loops endlessly. Then in each new damage stage, I tell the animator to play the new damage visual.

Unity Animator and Animations for Boss visuals

In the shield script, I added a resized shield that can spawn randomly, similar to the other enemy shields that spawn randomly.

Unity C# script for shield, scale up settings for Boss shield

The boss version of the shield also requires several hits to break before the boss can be damaged.

Unity C# script for shield, add condition for multiple hits on Boss shield to break it

In the Spawn scriptable object script that controls the enemy waves, I added a function for when the player wins to stop spawning.

Unity C# script or spawn enemy waves, add PlayerWin function

For the four damage areas, each gameobject consists of an empty game object with a box collider, Rigidbody, Mesh Renderer, Material, and a Mesh Filter Quad. Each damage area C# script contains a reference to the player to record damage and points, a reference to the Mesh Renderer, and the flash time for each hit visual.

Unity C# script for hit zone

The rest of the damage area script consists of collider checks for a hit from the laser, homing missile, player, or shield, and adds score and also records the number of hits to the hit zone. The script also includes a function to flash the hit zone red to make clear what part of the boss can be damaged.

Unity C# script for hit zone, flash color on hit and collision conditions
Unity C# script for hit zone, collision conditions (cont’d)
Unity C# script for hit zone, collision conditions (cont’d)

For the boss waypoint path, in the Game Manager script I added a new list of waypoints and assigned the set of waypoints in the Start method.

Unity C# script for Game Manager, different waypoints for Boss
Unity C# script for Game Manager, assign Boss waypoints

In the Boss C# script Update method, here’s the waypoint movement.

Unity C# script for Boss, waypoint movement

The last part of the updates is to add the game winning screen to the UI Manager script. Similar to the game over script, the winning message flickers, and we also show a restart option.

Unity C# script for UI Manager, game win messages
Unity Playmode with game win and restart messages shown

Here are some gif animations of various parts of the boss battle.

Unity Playmode, boss has random shield, 5 hits to destroy it
Unity Playmode, start of damage visuals
Unity Playmode, rest of damage visuals and game win message

Thank you for your time!

--

--

Chris Nielsen

An Engineering Manager consultant who is seeking additional skills using Unity 3D for game and application development.