Creating Modular Powerup Systems
Below we have six different power-ups: Speed boost, ammo refill, triple shot, repair ring, side-shot, and shields. They each have different functionality, but share many of the same behaviors. There’s no reason to reinvent the wheel with each new power-up. We can create a modular power-up system!
All the power-ups use one simple script, with just a few properties to set. And the only property that is different between these power-ups is the pull-down “Powerup ID” so the system knows which power-up it is.
We’ve made it easy to add new power-ups. We can simply duplicate one we already have, change its graphics and animation, and add its ID to the PowerUp script (it’s just a few lines of code, which we’ll get to in tomorrow’s article). The script will call the logic of the power-up’s effect elsewhere in the project. Now that the power-up is made with so little set-up, we can focus on implementing the power-up’s actual effect.