Modular Power-Ups in Unity

Power-Up Effects

My first goal was to make the overall effects of each power-up modular. So I created a scriptable object class called ‘PowerUpEffect’. This class contains an Enum to determine which stat is affected, a float, a bool, and a color. The float is used for stats like speed, and the bool would be used for something like turning on shields. The color is there to determine the color of the power-up.

PowerUpEffect class

Power-Up Instances

Next, I created a class called ‘PowerUpInstance’. This script inherits from Monobehavior and will be attached to the actual power-up game objects.

PowerUpInstance Class
PowerUpEffect Scriptable Object Asset.
Effects Assign in the Inspector

Powering Up the Player

Finally comes the part where the Player’s stats are affected. For this, I created a TriggerPowerUp method that takes in the enum for the StatAffected, and the PowerUpEffect being triggered. I then use a switch statement to match up the effects with the Player’s stats. There’s some UI stuff in there but that’s just for visualization in the demo and not crucial.

TriggerPowerUp Method in the Player Class.

Summary

The final result is that power-up objects can give the player multiple effects. Maybe you want to boost the player’s speed at the cost of health? Or maybe every time the player gets a certain Health power-up, their speed is temporarily reduced. This system allows for a lot of customization in how power-ups are implemented. Then, there’s the color-changing aspect that makes them more visually interesting. This part could also be expanded upon to include material lerping and other interesting effects.

--

--

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