Nerd For Tech
Published in

Nerd For Tech

Adding the Player Shield

Game functionality

Almost identical to how we set up the Player Health, Player Health Bar and Health Power Ups, in this article we’ll look at introducing a Player Shield System as well as linking it to a Shield Bar UI Element, and creating new Shield Power ups.

Creating the Player Shield System

To start we create a few new variables to initialise the Player Shield and to check if it’s active or not:

in the Player.cs

In Start() we set the current shield to the max shield:

current shield = 100 at start

Next we create a method allowing us to damage the Shield:

Similar to the TakeDamage() Method

Additionally in Update(), we execute another method responsible for deactivating the Shield when it depletes and in general for Shield behaviour outside of the DamageShield() method:


Now that we have a shield system in place we can basically mitigate the shield damage into normal damage for as long as the shield is active.

As soon as the shield is deactivated, it’ll continue to execute its logic.

Creating the Shield Bar

To create the Shield Bar I just duplicated the Health Bar, renamed it and inverted it on the x-axis. I set the fill Image color to blue.


In the UI Manager.cs, very similar to the Health Bar, we create two new methods (having a reference for it just like we have for the Health Bar); one allowing us to set the initial shield, and one to update the current shield. This time we wont be using a custom gradient as I don’t think it’s necessary for the Shield.

Having our methods updated the Shield Bar should now be functional.

Creating Shield Power ups

Likewise very similar to how we created Health Power ups, we can now manufacture the logic for Shield Power Ups.

Power up logic

Then we have to update our PowerUp Enum and the OnTriggerEnter() method in the Item.cs Script:

Now we can create three new prefabs that we can spawn:

In the following article we’ll be improving the Player Speed Boost, create a visual UI Element for it and add Speed Boost Power Ups to the Game.

Previous | Next




NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit

Recommended from Medium

How websites work tryhackme writeup

How to get a JSON file of your Medium Stats and create a Dashboard using Streamlit

Cream Fraîche — A Low Fat Protocol

Core Idea of Dynamic Programming problems

Get to know Imaginary Cloud

The Minimum Viable Stack — Part 1: Process and Guidelines

Custom Made Dakboard Alternative for Raspberry Pi — Part 3

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
Gert Coppens

Gert Coppens

Software Engineer — Unity Game and Application Developer

More from Medium

Adding a burst laser powerup

Unity’s Tilemap System

Damage VFX using Animated Sprites in Unity

Unity new Input System : Player Input Component (Part XII)