Powerups and How Long to Have Them

Sean Kaleomaikalani Ferreira
2 min readOct 27, 2023

--

In my articles I’ve been going over different aspects of game making by making a Asteroid-adjacent 2D Space Shooter. Now I want to add powerups and durations of said powerups, let’s start with a simple Triple Shot.

First things first, you probably want to be able to collect the powerup. For that check out my article on OnCollisionEnter vs. OnTriggerEnter that I have linked. Make sure you are using the correct variant when making your game!

Once your powerup item can collide with the player, you want to make sure the Powerup script (that presumably has your OnCollisionEnter function) can communicate with your Player script. My article on Script Communication in Unity Using GetComponent helps establish the connection needed, but suffice to say, you need to tell your Player script that it got a powerup!

An example of how you communicate to your Player script from anywhere else

Finally, you just flip a switch, add an asset, and the power is available! But how do you turn it off? I recommend a Coroutine.

If you don’t know what a Coroutine, go look at Coroutines in Unity for a rundown. It’s a simple implementation and you can pick how long the powerup lasts based on the wait variable!

--

--