Adding shields to enemies
Let’s go over the implementation of randomly adding a 1 hit shield to enemies.
In this article I added a shield to the player and we will use similar logic for the enemies.
Open up the enemy script and add a GameObject for the shield, a bool to check if it is enabled or not. Also add a SpawnManager to be able to check what the current wave is to ensure shielded enemies are not showing up too early in the game.
Initialise the SpawnManger in the Start function and add an if statement to check if the wave number is high enough. If it is high enough, randomly enable the shield:
Add the function for enabling the shield:
When the enemy gets hit by the player or by the projectile, disable the shield:
Lastly, add the shield object to the enemy prefab: