Space Shooter Ammo Count

Games Woods
2 min readMar 30, 2023
Photo by Crissy Jarvis on Unsplash

Objective:

  • Limit the lasers fired by the player to only 15 shots.
  • When the player is out of ammo, provide feedback through on-screen elements or sound effects. (ie: beep or ammo count displayed on screen)

Approach & Implementation:

Well this is a pretty easy one to crank out. Let’s make quick work of this.

  1. In the Player script. I create a variable for the AmmoCount and the Empty Ammo Clip sound.
    [SerializeField] private int _ammoCount = 15;
[SerializeField] private AudioClip _emptyLaserSound;

2. Next in our FireMainWeapons() method we decrease the ammo count by one for each shot fired.

3. Finally in our Update() Method we add logic that plays the empty Ammo Sound if the ammo count is equal to 0.

I’ve had a SoundCloud account for a long time! check out the profile pic circa 2005?! OK cool guy!

Results and Conclusion:

Adding a limit to the number of shots the player can fire introduces a new game mechanic/resource management element for the player to consider. This allows us to create an Ammo Drop Power up which we will add in soon.

Additionally creating an auditory cue for the empty ammo sound creates a cool immersive element to the game as well.

--

--