Spawning Enemy with Shield

Day 45- Making 2D Space Shooter Game

Objective: Making enemy spawn with shield which allows them to take one more damage

First we need to create a variable to store the shield and a bool variable to detect if the enemy has shield during spawn or not.

Now we don’t want this enemy to always have shield, instead we want the enemy to have 10% chance of spawning with a shield

We take the random number and if it is 5 then the enemy will have a shield during spawn. Note to write this code in Start.

Lastly create a condition to ignore one hit from player or laser and set the shield to inactive during that process.

Now the enemy can take one extra damage which will set the shield as inactive and the next time the enemy will get destroyed.



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