Creating Modular Power-Up Systems

For things like power-ups which usually appear in many different forms, making a script for each type is very inefficient.

Modularity is the solution.

A Speed Boost Power-up:

Not modular. Only works for this power-up type.
Speed Boost code

Let’s make it modular!

Add a Enum type variable
Create a switch statement to handle different power-up effects

In this implementation, I am passing the PowerupType _type variable and the float _duration variable to functions called ActivatePowerup(PowerupType, Float) which exist in the components that each power-up should effect.

This is not the only way to do it, but it works for my current project.

Now, rename the script, because it can work for all power-ups now!

Now it’s 1 script, but covers all 3 power-up types!

[EXTRA] For anyone still interested, this is how the Speed Boost code is now handled for my game:

This is on the Player’s movement script



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
Vincent Taylor

Vincent Taylor


Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.