Day 19 of my Developer Journey: Creating the Shield Powerup logic

Marek Ondrej Valco
2 min readDec 18, 2021

--

Objective: Create logic for a shield that takes 1 hit for the player

First we will set up our shield powerup as we set up those before. We will give it all of the properties we gave those before it in the inspector window, however we will set the ID to 2.

The inspector window of the Shield Powerup

Next we slightly adjust the random number value in the Spawn Manager so that it can spawn our new powerup.

Value in the randomPowerUp changed from 2 to 3

Now, lets set up how this will work. First, we need a bool to check if shields are active.

Bool that checks if Shields is active

Next we will create a void method to switch this bool.

When called, this will change our bool to true

Now for the logic of not taking damage for 1 hit. We will achieve this by ending the damage method early with the return command, which will happen after the variable was switched back to false. This we will do to avoid a bug which will makes us immortal.

Shields will protect the player from 1 hit only if they are false will this continue

Lastly we will call the shields method from our powerup.

Calling shields from the powerup

Objective: COMPLETED

--

--

No responses yet