Nerd For Tech
Published in

Nerd For Tech

Time to add shield charges

Today we are going to look at how we can increase the power on our shields and give a visual queue to the player so that they know when it is about to be destroyed. First, we will need to go to our player script and add a shield charge variable to work with:

From here, we can go into our player damage portion of the script and add in a switch statement to cycle through our different charges of the shield:

From here, we will set the desired charge value in our ShieldsActive void that we had created when we initially put in our shields, which that article can be seen here.

We have to be sure to put in place the adjustment of the sprite rendered so that whenever we collect a new shield powerup, we do not have our shield initially spawn with different colours like so:

Now that we have all of this new code implemented, we can test it our in our game and see if it works as intended:



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