Creating Modular Powerup Systems

When creating powerups, the developer can create a custom script for each one, but if there are many (the most possible), it doesn’t make sense

Instead, we can create a specific powerup script than can be attached to any powerup

  • Each powerup is a prefab, a GameObject
  • The behaviour of each powerup can be set using a switch statement in OnTriggerEnter function

Now, to spawn the powerups we use the SpawnManager GameObject and its script

  • In the script, we create an array of type GameObject to include all the powerups
  • The powerups must be assigned in the Editor
  • For instantiating powerups randomly, Random.Range can be used