Healing player with Health Collectable

Niraj Karki
2 min readMay 26, 2021

--

Day 35- Making 2D Space Shooter Game

Objective: Player heals when Player collects heath collectable

To make the player heal, first you need to add a health collectable which will then be used to update the player health.

After the health collectable is collected, call a HealthPowerup method in Player script.

When the HealthPowerup is called, we first check if the player is hurt or not by checking if the player lives is less than full. if the lives is less than full then add player health and update the health UI.

We also have a player hurt sprite active so we then set our player hurt sprite to inactive to show that player healed.

Now in the Spawn Manager, set a infinite loop inside a coroutine and make sure that the spawn time is larger to make it rare. We don’t want our player to heal every five seconds.

Make sure to call this routine from your start method or called method when game starts to start the routine and spawn health collectable.

--

--

No responses yet