Phase 1: Health Collectable

Objective: Create a Health collectable that will heal the player by giving back 1 life and update the UI visually.

I have previously written about creating a collectable and animating it. You can find those articles here: Creating PowerUp and here: Animating sprites

Once the collectable (powerUp) is created, I created a power-up called ship_repair and assigned powerup ID 4, we need to update the spawn manager. We need to expand the power up array and assign the Ship_Repair prefab.

In the Player script, we will need a method to add 1 life back and update the visual damage on the player as well as the UI element representing the player lives. I created a method called ShipRepair.

Ok, now it's on to the PowerUp script to call the ShipRepair method when the power-up is collected. I added a case to the switch statement for the power-up ID 4. The updated code is highlighted in green.

Let’s see this in action.

Happy Coding !!

Unity / C# Game developer