Space Shooter Features: Ammo Count

Damian Dąbrowski
2 min readJul 28, 2021

Ammo Count Feature:

  • Limit the lasers fired by the player to only15 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)

Solution Steps:

  1. Add a Text UI element to the scene and place it somewhere so that it does not affect the game area.

2. Add an “ammoText” variable to the UImanager script and assign the previously created Text UI element to it using the “[SerializeField]” option. Create an “UpdateAmmo” method to display the current amount of remaining ammo.

3. In the last step, update the player’s Laser method.

First create an “ammoCount” variable, then decrease its value after each laser initialization and update the ammo count display. Test the game. The code only counts single shots. A triple shot as a powerup is not counted against the ammo count.

--

--

Damian Dąbrowski

Hi, I’m Damian, a Software Engineer who loves building educational apps and simulations..