Unity Basics: Determining How Long Powerup Effects Should Last

Powerups in a game should have some sort of limited duration, otherwise our game would not be challenging at all. We can achieve this by using coroutines. We have already used coroutines for the spawn manager to spawn objects every 5 seconds. Furthermore, we can also use coroutines to specify how long we want the effects of powerups to last.

To specify whether our powerup should be active or not, we can use boolean variable.

The next step is to create coroutines for powerups.

For both powerups the deactivation countdown is set to 5 seconds, for triple shot we simply activate the function and deactivate it after the specified time. For speed powerup we increase or decrease the speed variable by multiplying or dividing by the speedUp variable respectively.

As you can see, curoutins are quite useful and very commonly used in Unity.

--

--

--

Hi, I’m Damian, a Unity Software Engineer who loves building education and simulation games.

Recommended from Medium

Integrating LVM with Hadoop and providing Elasticity to DataNode Storage

Lame Encoder For Mixxx

Animating player | Unity

NFT- Weekly Digest | Week 05

Using Amazon SES to send mails from a Ghost blog

Approaching HIPAA Compliance

READ/DOWNLOAD@< Data Abstraction & Problem Solving

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
Damian Dąbrowski

Damian Dąbrowski

Hi, I’m Damian, a Unity Software Engineer who loves building education and simulation games.

More from Medium

Animating Sprites In Unity

Wrapping Up the Introductions

How to Win the Race Using Director

Moving Platform and Lives