2D Galaxy Shooter: Ammo Collectable
PowerUP that refills the ammo count allowing to player to fire again..
In my last article , we have mentioned that player fires laser as they have max limit of 15 shots and when player is out of ammo, there is no way to fire it again. So another feature that refills the ammo count back to 15 shots — ammo collectable.
This can be achieved using Prefab — Ammo_Powerup referenced in Powerup.cs script and set the properties in inspector such as Powerup ID =3 speed, audio clip etc .
In Powerup.cs script it will call OnTriggerEnter2D() method when Player collided with the powerup ammo collectable having _powerupID =3 it will communicate with the Player.cs script call the method having player reference player.AmmoPowerUpActive() as below
In Player.cs script, where the purpose of AmmoPowerUpActive() to refill the _ammocount variable back to 15 and communicate back to UIManager.cs script, so that it will display on UI Canvas.
It will call _uiManager.UpdateAmmoCount() method as discussed in last article where it update the ammo back to 15.