Create a Color Changing Shield in Unity

Objective: Change the Player’s shield to take up to three hits and change in color to indicate the shield’s strength.

The first thing we will need to do is go to our Player script and add two variables:

The first is a reference to the shield itself and the second is the number of hits the shield will be able to absorb.

In the Method that controls when the Player takes damage, we can create an if statement that dictates if the player’s shield is active. When the shield is active a switch statement will use the shield strength variable we just created to change the color of the shield:

Case 0 will turn off the shield and change the color so the shield will be full strength when the player picks up another shield powerup.

The last thing to do is set the shield strength to 3 whenever a shield powerup is picked up:

Learning to become a unity game developer