Creating a modular PowerUp System in Unity
Objective: Create an extensible and modular PowerUp System.
Requisites: C# fundamentals. A single PowerUp script that will handle the conditions by ID.
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
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:
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.