Creating a negative pickup in Unity
Objective: Create a powerup that will negatively effect the player
It is time to introduce a negative powerup into the space shooter which will take away the player’s current ammo count
If the player collects the powerup they will have their current ammo amount removed and replaced with the negative amount and the image will change to let them know.
To make this work we will need a few things:
- A prefab for the negative powerup
- A new negative ammo count sprite
- New method in the player that communicates with the UI manager.
Once the prefab is made it needs to be added to the spawn manager that holds all of our powers that can spawn.
In the powerup script a new case needs to be added for the new powerup.
First we call our new AmmoDeplete method, then play the correct audio source associated with the powerup collection.
The new method is very simple and uses a method that has already been made in the UI manager script. I am updating the UIManager with the correct array position for the newly created ammo depleted sprite.
Updating the currentAmmo variable to 0 will make sure that the player will no longer be able to fire until they collect the ammo powerup.
And that’s it for adding a new powerup that will negatively effect the player.