Making the Shield More Powerful

Now it is time to make the shield a little more powerful by giving it the ability to take 3 hits. To do this you will need a variable to keep track of how many hits the shield has left and when that points to the sprite renderer for the shield so that you can adjust the color of the shield as it takes hits. Create these at the top of the class with the other variables.

Next, in the start function initialize the variables.

Next, update the ShieldActive function. Set shield hits left to 3. Adjust the scale of the transform so it is slightly bigger than normal. As the shield takes hits it will decrease back to its normal size. Set the sprite renderer of the shields color to something bright like white so it stands out when it is at full power.

Last, you need to update in the Damage function where it checks if the shield is active. When the shield takes a hit you want to decrease the number of hits left. Then add a switch statement to handle the different scenarios for the number of hits it has left. As it has less hits left you want to reduce the scale of the shield visualizers transform and also change the color to show that it is not as powerful.

That’s it! Now when the shield takes a hit it lose power until it is gone.

Good Luck Adventurer!




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store