Powerup lifetime and effect?

How long should our triple shot last and how does our shield protect us?


Okay so… After creating a pickable powerup that moves down.
We need something to determine how long the powerup effect will last. It can’t last forever, right? That would be just unfair, haha :D

So let’s start creating this mechanic and get momentarily powerful! :)

Triple Shot

For triple shot we need
Boolean (To know when our powerup is active)
(To determine how long the powerup lasts)

When player pickups our triple shot powerup, this code runs

And this is our code in coroutine which we use! :)

So after picking up the powerup, we wait 5 seconds and set _tripleShotActive to false.

Nice! Now we have Triple Shot which lasts 5 seconds! :)

It depends on what kind of powerup we have on our plate. Now I’m going to show you how to create a cooldown for my favorite powerup, SHIELD.

Making this we need
SetActive (To show the shield game object)
(So we know when the powerup is active)

Shield powerup

Shield game object is a child to our player so it follows the player as we move

What happens after we change our boolean _shieldActive to true?
We know now that it’s true but what happens?
Our Shield shows but does it protect us? NO… It doesn’t yet.

So what our shield does? It protects the player for one hit. And we need to check the hit and boolean from the code where we damage the player.

So if _shieldActive is true, the next hit we take is not going to affect us and it will set _shieldActive to false and SetActive to false.

Awesome! Shield and Triple Shot are active! :)

Thank you for reading this and hope to see you in the next one!

Photo by Adi Yusuf on Unsplash

From the beautiful snowy country with a touch of "good" humor? Inspired Unity Developer to learn more.