Sitemap

Buffing up the Player Shield!

2 min readMay 7, 2021

We already have a shield powerup in the game… but it feels somewhat lacking right now. That’s why today, we are going to take a look at how we could buff it up a little bit!

Press enter or click to view image in full size

Objective:

Allow the shield to withstand three hits before collapsing. Visualize current shield strength.

Implementation:

First up, I have decided to visualize the current shield strength with the color of the shield itself. I have decided to go with a blue = full power, purple = damaged, red = almost depleted.

I have created an animation for each color and set each animation as a different ‘State’ in the ‘Animator.’- the ‘Transition’ tracking is done via an int ‘Parameter’ I have called ‘ShieldStrength.’

Press enter or click to view image in full size

I have also decided on creating a new script, ‘ShieldBehavior,’ which controls…well, the behavior of the shield.

Here I have created three methods:

  • AreShieldsActive() - This method returns a boolean variable that stores whether the shields are active or not
  • ActivateShields() - This method turns on the shield powerup, and if they are already on, sets the HP value of the shield to the maximum.
  • DamageShields() - This method is responsible for decreasing the shields' HP and switching up the animator transitions. Also, if the shields are fully damaged, turn off the shield GameObject.
Press enter or click to view image in full size

Now all I need to do is to change the ‘Damage()’ method in the ‘Player’ script.

Now the shield power-up is a bit stronger and can withstand more shots - it may seem more alluring for the player to risk trying to pick up the power-up!

But that is it for now, thank you for reading and feel free to follow me for more articles - and as always, good luck and see you next time!

--

--

Matej Marek
Matej Marek

Written by Matej Marek

Aspiring and eager beginner Unity developer

No responses yet