Every challenge is a good opportunity improving the skill to defeat a game. To raise up the level of challenge, giving our enemies some buff might be a good start.
In this article, we will make our enemy got shield protection randomly. It is getting tougher for our players to clear them all.
First thing we need to do is to create a shield prefab, which we can easily create one from the Player.
Inside our Player, there is a shield gameobject which is not a prefab yet. We can simply drag it into Project as a new prefab.
Then we need to attach this shield prefab into the Enemy prefab.
We should deactivate it in prefab and call it later in the script.
With this, we can randomize it in the script.
Randomly shield setting
In this script, we will need 2 variables to use shield.
In the Start(), we will let the God of Random to decide who should get the shield.
Then we also need to adjust 2 method to enable the shield effect.
First is the LaserHit().
We shall do the shield test first. If it is protected by shield, then disable the shield, which is what we need for a 1 time protection.
Use the same statement in OnTriggerEnter2D().
All done! We can play it now to see who would be the lucky one.