Galaxy Shooter: Shield Strength Visualization

In this article I’ll show how I setup my shield strength system.

My shield is setup to take 3 hits before being disabled, I have it change from blue to yellow/orange on the first hit, red on the 2nd hit and disabled on the 3rd hit.

This could probably be done more efficiently with a shader but I’m working with the assets included in this project. I duplicated the blue shield sprites and made copies in Photoshop with different colors.

I then added them to my player in the hierarchy and disabled the gameobjects so that my Player class can enable/disable them.

In my Player class I then added variables and serialized the fields so I can drop them in in the inspector.

Inside my Damage method I manage the shield when the _isShieldActive bool is true.

As you can see I use a switch statement checking for the value of _shieldStrength and I decrement 1 from _shieldStrength each time it’s hit and enable/disable the different color shield’s gameobjects.

To fix the bug of 2 different color shields enabled at once if another shield powerup is collected while my shield is damaged, I reset everything to its correct starting state in my ShieldEnable() method which is called when the powerup is collected.

Unity Developer/C# Programmer for VR, 2d,3d Games and other Immersive Interactive Experiences