2D Shooter: Limiting Ammo Supply
Objective: Limit the amount of times the player can shoot and create a way for the player to keep track of how many bullets are left.
I started by making an int variable equal to 15 for the ammo available.
Now let’s go to to where we call the method to fire the laser and add some code that subtracts one whenever a laser is fired.
Now let’s go to Unity and create a visual counter for our ammo. This will be quite similar to when I made the score system here. You can make it how you want it, in the end I decided on this:
Like with the score, we’ll want to attach it to a text variable in the UIManager script. Once you’ve done that, make a new method that will update the Ui element with the number of ammo left, and make it blink when it hits zero.
Now the player has been successfully hindered and can’t kill more than fifteen enemies. We’ll make a way to add ammo next time.