Creating a modular PowerUp System in Unity

Objective: Create an extensible, modular and easily debuggable PowerUp System.

Requisites: C# fundamentals. A single PowerUp script that will handle the conditions by ID.

Example of a PowerUP script in the Inspector

In order to architecture our game decently, we want to create a modular system easily scalable by just adding the new implementation and a new ID.

The first step is creating an int ID variable that will tell wich PowerUP is each one

IDs for our PowerUPs

On every PowerUP prefab we have, we need to give it an ID in the Inspector.

Remember: Good practices in programming say that we should always keep every variable private unless the value is going to be accessed and modified by an external script.

Right into the implementation, when we collide with the Player, we get the player reference, null check it and here comes the magic:

Switch PowerUP handler

A simple switch handles the PowerUP ID from the Inspector and calls a method on our Player that activates the correct one.

And that would be it, now we have a robust system that will be easily scalable.

Passionate Unity developer always looking for new challenges!

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