Space Shooter Features: Ammo Count

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.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store