Galaxy Shooter: Ammo and Health Powerups

Andrew Crippen
3 min readJul 6, 2021

--

For my ammo and health powerups I made new sprites in photoshop and then animated, attached a collider and rigidbody same as my other powerups and then prefabbed them in Unity with my Powerup script attached. (For the Health powerup/pickup I also added a different sound that plays when it’s collected.)

For the ammo powerup I gave it the _powerupID of 3, the health _powerupID is 4.

I also dropped them into my Powerups array in my Spawn_Manager.

When collected the subscribed method in the Player class and AudioManager class are sent the powerupID and the AudioClip attached to the powerup as you can see in the OnTriggerEnter2D method in my Powerup class.

Player class subscribing and unsubscribing
My AudioManager class

Now in my Player class in my PowerupEnable method I added the cases for the powerup ids 3 and 4 in my switch statement and added the logic for their methods to be called.

When the Ammo powerup is collected it runs the following code…

It adds 15 to my ammo count, checks if the ammo count is now greater than the max ammo count and if it is then it sets the ammo count to the max ammo count.

It then invokes the OnPlayerAmmoCountChange event which sends the info to the UIManager to update the on screen values. (I changed the name from OnPlayerShoot to OnPlayerAmmoCountChange so that the name is more fitting for anytime the ammo count changes not just when the player shoots.)

When the Health powerup is collected it runs the following code…

It adds 1 to my Lives property, checks if it’s more than 3 and sets it to 3 if it is which is the most the player can have since there are only 3 lives on screen. It then repairs the player’s engine damage by turning off the engine damage animated gameobject depending on how many lives the player now has. Lastly it invokes the OnPlayerDamage event and sends the Lives int to the subscribed UIManager to update the graphic on screen.

--

--

Andrew Crippen

Unity Developer/C# Programmer for VR, 2d,3d Games and other Immersive Interactive Experiences