Objective: Create a powerup that restores the Player’s ammo when collected.
We will be adding to the modular power-up system we created in this Article.
The first thing we need to do is create the powerup, give it a rigid body, collider, and powerup script:
Now in the Player script, we need to create a method that will refill the Player’s ammo count to the maximum ammo count when collected:
In the Powerup script we need to create a case in our switch statement for the ammo powerup to call the new Method and assign the powerup’s ID in the Unity Inspector:
The last thing that needs to be done is the powerup needs to be added to the Spawn Manager so the powerup will randomly spawn into the game: