Building a Better Shield (Game Dev Day 34)

Jack Leavey
3 min readSep 20, 2021

Objective: Make the Shield powerup block 3 shots instead of just one. Include visual feedback for the player.

As of now, the Shield powerup is pretty weak. It only blocks 1 shot, and only for a 5 second duration. Currently our enemies fire 2 projectiles at us, meaning the shield cannot defend against a direct hit.

Let’s add some extra padding to this powerup to bring it up to the quality of the other two (triple shot, speed boost).

First let’s create 2 more shield Gameobjects.

I have numbered them according to their strength (3 is full shield).

Next, I change the color of the two weaker variants of the Shield. The 3/3 Shield stays blue. The 2/3 becomes a greenish/yellow, and finally the 1/3 is red.

Cycling the Shield variants.

Now we need to add code to make them cycle and still block damage.

But first, we need a total of 3 Gameobjects loaded into our Player script.

Now we add our three GameObjects from the Hierarchy window

Adding our GameObjects to their respective positions in our script.

Next, we need to make some changes to void ShieldActive.

This just states that picking up a shield powerup item in-game will reset the shield to the strongest value.

Then, we need to make a few more changes to the ShieldPowerdown routine.

We changed the time value to 15 seconds from 5 to buff this system.

Essentially, after 15 seconds have passed, this will disable any of the active shield visuals AND turn off the shield effect that blocks the damage.

Finally, we can implement a series of if and else if statements to achieve our goal.

This script checks to see which stage of the shield we are on, then moves us to the next stage when taking damage. Once the “Red” shield is broken, we lose our shield entirely and can now lose lives again.

In the future, I may change the enemy ships’ projectiles to only count as 1 hit instead of each individual laser counting (so each shot can hit you twice if both lasers connect). But for now at least our shield is a powerful buff alongside its brethren.

--

--

Jack Leavey

I am a software engineer with years of experience branching into game development, specifically in Unity. Follow along for guides on creating game mechanics!