Day 18 | Determining How Long Powerup Effects Should Last

Ted Lim
2 min readApr 14, 2021

Powerups are fun to make, but having permanent powerups might make your game too easy. In this article, we’ll go over how to make temporary power-up effects.

2D Space Shooter Example

In my 2D Space Shooter project, I have a powerup called Triple Shot that allows a player to shoot 3 lasers instead of the normal 1 laser. To enable Triple Shot, the player must collect the Triple Shot power-up. When it’s collected, the powerup tells the player that the Triple Shot ability should be enabled.

Our goal is to find a way to turn off the Triple Shot ability during the game. Since the Triple Shot ability is controlled by a boolean value called _canTripleShot, we want to create a way to schedule _canTripleShot to become false. Since we are trying to schedule an action, we’ll use a coroutine to solve our problem.

We create an IEnumerator called DecayTripleShotTime that allows us to define a timeframe for how long we want the Triple Shot ability to be on. We’ll create a private instance variable for the timeframe and call it _tripleShotDuration.

Now, when we turn on the Triple Shot ability, we also call our coroutine. Once the allotted time passes, we reset our boolean _canTripleShot to be false and wait for the next time a player collects the Triple Shot powerup to turn on the ability. Pretty cool!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response