A Modular script, is a better script!

Now although in the previous article I had made a powerup, that is not going to be my only powerup. Due to this I should not make a separate script for each new one, but can I just use the same script? For the most part, yes.

For now I plan to have at least 3 powerups in total, the Triple Shot, Speed up, and a shield. If I want to use the same powerup script on them all I need to make some kind of differentiation between each of the prefabs. That comes in the form of a Powerup ID.

Creating this variable allows me to in the inspector on each prefab, apply a ID number on each powerup. Remember that any changes on the inspector take precedence over the code and will save until you change it.

With this I can just make if statements on if the _powerupID equals 0, 1, 2, or something else!

This way I don’t need to make a separate powerup script for my future 20 powerups!

Though, there is definitely a better way to do this than if and else statements.

I’ll get back to you on that next article!