Adding a Shield Strength Mechanic

Ahmed Mubarak
2 min readAug 27, 2023

Objective: We want to essentially give the player’s shield a lives system of its own, making it take 3 hits before it gets destroyed, along with visual cues to convey this.

We can do this in multiple ways, but the way we will do it is by duplicating our existing shield — along with its animation — twice, and changing the color on each copy. We also need references to these shields from our Player script.

Now we activate each one based on how many hits the shield has taken. First, we need a variable for shield “lives” just like player lives:

Then, in our Player’s Damage() method, we reduce the shield’s lives by 1 if it is active, and then check if it has been hit once, twice or three times. Once we know this, we activate the corresponding shield and deactivate the others:

Once we know they have all been destroyed, we need to reset the shield lives for next time the powerup is collected. We do this in our existing ShieldActive() method that we use to activate the original shield:

And that’s it!

--

--