Creating a Enemy Weakness

Ryan McCoach
3 min readJun 21, 2021

--

In this article we will cover how to switch between two enemy behaviors. This article is a continuation of two previous articles that covered the enemy dodging the player’s shot and the enemy constantly rotating and shooting at the player. I am just covering how to go between these two behaviors.

The objective of this new enemy behavior:

  1. When NOT firing the enemy CAN dodge the player’s shot.
  2. When firing the enemy CANNOT dodge the player’s shot.
  3. This gives the player an opening to attack this kind of enemy.

We need to track whether or not the enemy is firing since this is when we want to take away the enemy’s ability to dodge. This will be a boolean and we will set it to FALSE.

We always want to be either using the Dodging or EnemyFire method and we only want one to be called at a time. Let’s check to see if our _isFiring is either TRUE or FALSE? If it is FALSE then the enemy can only Dodge and if it is TRUE the enemy can only FIRE.

When we are in the Dodging method we are going to start a Coroutine (StartFiring), which will wait a set amount of time before setting _isFiring to TRUE.

When we are in the EnemyFire method we start a Coroutine (StopFiring).

This Coroutine will wait a set amount of time before setting _isFiring back to FALSE.

These two methods will bounce back and forth because these Coroutine set the _isFiring variable ON and OFF (TRUE and FALSE).

--

--

No responses yet