Creating a Shield Powerup — Part 2, The Visual Shield

Last article we created the Shield Powerup Collectible and gave our Player some logic for when they collect the powerup.

But it would be much better if our Player could SEE when the powerup is active. In this article, we’ll give our Player a colourful shield, and activate/deactivate it when necessary!

Our final Shield!

The Shield Game Object

We have a Shield Sprite, so the first thing we’ll want to do is connect our Shield to our Player and position it accordingly.

We’ll make out Shield a child of the Player, so that the shield will follow the Player’s movement:

Shield connected as a Child.

Now within our Player script we’ll create a reference to our Shield GameObject _playerShieldVFX.

Shield VFX reference inside Player script

And then link our childed Shield Game Object inside the Player’s Inspector:

Player_Shield linked in Inspector.

Activating/Deactivating the Shield

To activate or deactivate our Shield, we’ll go into our Player script again, and modify our Activate/Deactivate functions.

Since we have a reference to the Shield’s GameObject, we can simple call _playerShieldVFX.SetActive(bool) when we need to enable/disable the shield:

SetActive() enables or disables the Game Object it is being called on.

And the code in action:

Big Blue Shield!

Shield Animation

Our shield works, and that’s great. But it’s a little stale. Let’s spruce it up with a simple animation!

With our Shield Sprite, we add additional sprites to be used for animation. But after setting the animation up, we run into a little VFX bug:

Shield VFX bug: it glitches in front and behind our Player.

This is an easy fix — we just have to change the Order in Layer for our Player to be on top of the Shield at all times. We do this by incrementing the Order In Layer to 1:

Increase the Order in Layer of the Player

And that should resolve our issue!

Shield VFX Fixed!

Now our Player knows when they have a shield and when it gets destroyed! This is a very helpful visual cue for our Player when they are navigating through our game!

Final Shield example

Audio Engineer turned Unity Game Dev. Will be combining both my skillsets when appropriate, and will be documenting my Unity Dev growth in these Medium Articles