Creating Ammo Collectable in Unity
Reload ammo during the game!
Objective: create a collectable to add more ammo when the player collects it
First I dropped a sprite in the scene, modified the size and added the components (collider and rigidbody) to create the ammo prefab.
Also I added the powerup script to this prefab because it is gonna have the same behaviour than a powerup. The player collects it and executes something.
In the SpawnManager Object I added the ammo prefab to the powerup array.
In the player script I created a function called “AddAmmo” to modify the value of the ammo variable and update the UI.
Next in the powerup script I added a new case to call the function to add ammo.
And that’s it! Ammo collectable ready.