New Enemy: Mine Layer Pt 2

Thomas Kesler
3 min readJun 14, 2021

In my last Article, We looked at how to make a proximity space mine. Now we need to look at how we get those mines into space, The Mine Layer itself.

This Enemy will borrow most of it’s code from the Basic Enemy type and will show similar behavior, to a point. Once it has detected that it is behind the Player’s position, It will lay (disperse) between 1 and 5 mines on either side of it’s own path. The is also some delay between when it Knows it can deploy and when it does, otherwise we may end up with a solid line of mines, if the Player decides to stay near the middle of the play-field for instance. Now let’s look at the differences that make the Mine Layer.

Foremost, we have two new Variables, _mineCount and _maxMineCount. With _maxMineCount Serialized for the Designers, We allow them to determine how many Mines the Enemy can have.

As with the Aggressive Enemy, we adjust the Awake() so that the Enemy always gets a reference to the Player, it’s target.

We use this Bool to check the Enemy’s position in comparison to the Player’s. Once it returns True, the Enemy knows it is in a Position to deploy mines.

Here we have the Coroutine that launches the mines. There is a random Float that we use to set a delay before the deployment. The While loop gives us a tighter deployment line, remove to get a more V shape to the deployment. Then we have to Nested For loops. ‘i’ is for the number of mines. ‘x’ is for each side. So, we drop the Mine on the Left then the Right and count that batch as 1 mine. This way we get the same number of mines on each side of the Enemy.

These two work together to give us an additional check in our Weapon().

And we add a ReloadMines() that we can call in the Respawn method to reload the Enemy for their next pass.

And with that, we have a Mine Laying Enemy that wants to make the Player have a bad day.

--

--

Thomas Kesler

A Unity Developer with a fondness for Fantasy games and the challenge of pushing boundaries.