2D Galaxy Shooter: Health Collectable

Health PowerUp that heals the player by 1…!!

Anurag Chawla
2 min readJun 3, 2021

In our 2D Galaxy Shooter, player firing laser to enemies and enemies back fires to player and during the play of course — Player loses its life..Currently there is no way for player back to game if player looses all lives

For these situation added additional feature— thats we call Health Powerup that provide player back 1 life or heals the player by 1.

Health Powerup can be created using Prefab- Health_Powerup referenced in Powerup.cs script and set the properties in inspector such as Powerup ID =4 speed, audio clip etc same way as we did in last power up Ammo_PowerUp

Created Prefab: Health_Powerup
Script PowerUp.cs — having _powerupID of 4 for Health

In Powerup.cs script it will call OnTriggerEnter2D() method when Player collided with the powerup health collectable having _powerupID =4 it will communicate with the Player.cs script call the method having player reference player.HealthPowerUpActive() as below

Script PowerUp : OnTriggerEnter2D() method logic for health powerup when player collided

In Player.cs script, where the purpose of HealthPowerUpActive() logic to update the health of the player live, update the engine left or right accordingly communicate back to UIManager.cs script, so that it will display on UI Canvas.

Script Player.cs : logic for HealthPowerUpActive()
Script UIManager.cs : UpdateLives() method to update the lives to reflect on UI canvas.
Health Collectable:Heals the Player by 1…

--

--

Anurag Chawla
Anurag Chawla

Written by Anurag Chawla

Emerging Technologies - Power Virtual Agents | AI Chatbots | Multi-Cloud & DevOps | UI Technologies - React , Angular | Gaming Technolgies - Unity, XR- AR/VR

No responses yet