How to Make a Modular Powerup System for Unity

Sean Kaleomaikalani Ferreira
2 min readNov 5, 2023

--

So you have a few too many powerups for multiple functions? Let’s figure out how to organize it!

A start to a simple fix

Say you are making a New Super Mario game, you have to deal with standard Red Mushrooms, Fire Flowers, and even Penguin Suits and Propeller Mushrooms! You aren’t going to make a Collider case for every powerup, not unless you’re crazy. You’re not crazy, right?

Good, for now, you should try assigning an “ID” to your powerup. Say Red Mushroom’s ID is 1 and Fire Flower’s is 2 and so on and so forth. This way, you can have a simple collision function.

Alternatively, you can make the Collision function the place that parses out which powerup is what (if _powerupID = 1, go to the Player.RedMushroom() function). It’s also a great time to use switch-case, which you should be able to look up on your own, but to quickly go over it; Switch-case acts as larger If-Statement based on one variable

Either way, you will end up in your Player Script to get the powerup online. In my case, my Modular System is in the Player Script with the Powerup() function.

This way, all powerups are slapped into the same Powerup() function and cleans up the code a little bit.

--

--