Day 21: Creating Modular Powerup Systems
Objective:Create a modular power up system
In our game we will have multiple power ups. It doesn’t seem smart to create a different power up for every single power up when the logic is very similar. So we will make our power script modular.
To start off we need a way to identify which power up is collected. We will add a int powerupID. We made it a SerializeField to set the ID in the inspector. Here is a good spot for a comment. The comment allows for other developers to know what ID is for what.
Next will be to check the powerID at the time of collection. Right now the logic for the speed boost and shield haven’t been implemented. So for now we will just use debug.log.
The logic on collecting different power ups have been set. Next thing we will do is go to each power up prefab and set their correct ID.
Now when you collect the speed power up, the console will have a message printed in it when the speed is collected.
That is how we created a modular power up system. Later we will optimize it to make the code look more clean.