The Boss Enemy, Part 3

Objective: give the boss another attack pattern with beams

The next attack pattern will be create through a new BossState called BeamAttack. The goal here is to have beam weapons that track the player as they charge, then fire on the player position after a brief delay. We’ll need to set up the gameobjects in the hierarchy and have variables in BeamAttack to keep track of them.

In order to organize all these game objects, we’ll use a struct. This is similar to class, except that it’s mainly used for holding data. By making the struct serializable and then serializing all the fields, we are able to set all these game objects in the inspector to keep track of them.

Now we can utilize these game objects similarly to how the dodging enemy uses its beam attack. Since we want to allow the boss to track the player, wait a moment, and then fire, we can use a finite state machine within this state class!

BeamAttack enum. It’s a state machine within another state machine.

To setup this attack, we’ll start in the Tracking state, set the charging sprites to zero scale, and start the warning line flashing for both beams. We also make sure to keep track of the rotation of the entire beam objects so we can control them as they track the player.


This coroutine causes the warning lines to flash. They will flash faster once the beams have “locked on”, in order to let the player know they are about to fire!

While tracking, we increase the size of the charging sprites over time, while also rotating the beams toward the player (as long as the player exists of course). We use a new EnemyBehavior helper method to rotate the beams in the proper directions.

BeamAttack methods

Finally, when the state is changes to locked, we will wait some time and then change to the Fire state. This calls FireBeams which turn off the charging sprite and turns on the actual beam attacks that can damage the player.

BeamAttack methods

Finally, when the boss leaves the BeamAttack state entirely, it will call EndState which turns off the beam attacks and resets their rotations, to ensure they will be set up properly for the next time the boss uses this beam attack.


Now the boss has a pair of deadly new weapons in its arsenal, and extremely flashy ones at that!




I’m a passionate and talented software engineer seeking an opportunity in game development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Distribute your android apps with Firebase App Distribution Gradle plugin(Bitbucket Pipelines…

Espresso unit testing and things to watch out in Android

Kotlin coroutine dispatchers overview

What 2 Years of Android Development Have Taught Me the Hard Way

How to Set Background Image to Scaffold in Flutter — Akshar Mangukiya

Quick Recipe for creating DSLs in Kotlin

Firebase with Jetpack Compose — Cloud Firestore

Coverage Reports In Android and SonarQube

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
Blake Zoeckler

Blake Zoeckler

I’m a passionate and talented software engineer seeking an opportunity in game development.

More from Medium

Connecting GitHub to Unity

Making a Dash Mechanic for your game

3D Pose Estimation with Media Pipe and OpenPose

Unity : AI [Navmesh implementation (Part III)]