2D Galaxy Shooter: Ammo Count
Visualize on screen the ammo count of the player in the form of current/max
This feature of Ammo Count in the form of current/max—here we have assumed that default max of ammo count player having 15. so when player start the game having Ammo Count :15/15 .
This can be visualized by adding Text from UI under canvas- with few properties set for Text like alignments and setting Text as Ammo Current\Max:
Programmatically in-order to visualize this, there is a communication between UIManger.cs and Player.cs Scripts.
In Script UIManager.cs - added variables as below and during start of the UIManager.cs script, it will initialize the _ammoCount.text Text field.
private int _totalAmmoCount;
private int _totalBaseCount = 15;
Here TotalAmmoCount() method is called in Player.cs script in order to know the player the total ammo he is having.
As when player shoot laser — deduct 1 ammo from Total and as when player acquire Triple-Shot power- up & fires 3 lasers, so deduct 3 ammo from the rest of the Total ..This happens in FireLaser method()
When AmmoFire() method is called, it will update the ammoCount based on either laser is called 1 or 3 (for triple-shot) and it will call the updateAmmoCount() as discussed earlier and update the UIManager.cs script.
Finally when game runs..and player fires laser …and see as below..
- Limit the lasers fired by the player to 15 shots.
- When the player is out of ammo, provided feedback through on-screen elements flashing Total Ammo:0