Today, we’re going to be adding depth to our shield system. We will be altering the shield to allow three hits, but visually change when each hit occurs. This will give the player feedback that they were hit by an enemy or a projectile.

Open your ‘Player’ script and we’re going to create two new variables. Both will be serialized, but one is a private ‘SpriteRenderer’ named ‘_shieldRenderer’ while the other is a private integer named ‘_shieldStrength’ and set this to 3.

In our ‘Damage’ function we’re going to change up our if statement about ‘_isShieldsActive’ being equal to true. We will first decrease the shield strength by 1 when hit. We will then write out a switch statement for ‘_shieldStrength’. Case 0 will be the final shield bubble. We will keep the ‘_isShieldsActive = false’ and the ‘_shieldPrefab.SetActive(false)’ in here. We will then change the color of the sprite renderer to whatever color you wish. I’m choosing cyan to allow the player to visualize that the shield is in terrible shape. We then call a break.

Case 1 will see us change the color of the sprite renderer to whatever else we want. I chose red for this one. We will follow that with a break. Case 2 is the same with another color. This color is the first color the player will see when they pick up a shield.

Finally, in our ‘ShieldActive’ function, we will set ‘_shieldStrength’ to 3. This will reset the shield counter each time we pick up a new shield powerup. Save and hit play to see what you get.

The post-processing settings I have for my project are what make my shield colors a bit off. The final form should be red, but my settings are making it a pale green/blue.