2D Shooter: Shield Strength

Objective: Increase the strength of the shield with each collected powerup so it can take up to three hits before breaking, and create a visual element to keep track how many hits are left.

First, let’s add these two variables to our script, I put them near our variable for the shield visual for organizational purposes:

Now we need to get the sprite renderer component and assign it to to _shieldColor by using GetComponent() in the start method.

Now let’s go to the method that activates the shield powerup. We’ll want to increase _shieldLife here and make some conditions that explain what color we want the shield to take when its at a certain amount of points.

Now we’ll want to do something similar in the damage method, where we want the shield to go back to a certain color whenever it takes damage.

We want to return; after each statement so that the code doesn’t continue and removes life points from the player. But once this is done, you should have a shield that can take up to three hits once you collect three shield powerups.

Currently learning to code with the help of GamedevHQ in order to someday my my game ideas come to life!