In this article, we are going to beef up the shield so it can take more than 1 hit before being disabled.

The Player script has the Shield PowerUp method and we will need to adjust the amount the shield can take before being destroyed, so we will declare a int variable that will set the amount of hits the shield can take.

Taking a look at the Shield Power Up method, we need to check to see if the the Shield is already active because we want the player to only be able to pick up the Shield Power Up if they do not already have it. So, if the ShieldActive is not equal to true we will set it to true, set the Shield Strength (which determines how many hits the Shield can take), activate the Shield Visualizer and set the color of the Shield Visualizer. The Shield Visualizer is already the color of Cyan, but as we will change the color as it takes hit, we do not want to default to the last color so we need to reset each time it is activated.

We will need to get access on to the Shield Visualizer’s Render so we can change the color. Serialize a Sprite Render variable and we will assign it in the Inspector.

In the Player Damage Method, we want check to see if the ShieldActive is true, which is set when the Player picks up the Power Up and the Shield Strength is equal to or less than 3 (so this continues until we are out of hits). When the Player is hit, the Shield Strength will be subtract by 1 and we will check the current value of the Shield Strength. If it is 2, we access the Sprite Render and change the color to Magenta, if it is 1 we change it to red and if it less than or equal to 0, we turn off the Visualizer and Shield Active. This puts everything back to their original settings before the Power Up is picked up, so the same thing will happen again when thePlayer collects another Power Up.