New Feature — Health Collectible

Reward the player with an extra life

Jean-Noel Seneque
3 min readJun 23, 2021

Objective: Give the player an extra life when they collect a health powerup and update the on-screen UI

Creating new power-ups is super easy with the way we created this modular system. We are going to follow the exact steps we did in the last article for the Ammo Power-up.

Create Health Power up Prefab

Make a copy (duplicate) of the Ammo power up by selecting it and pressing CTRL + D

Let’s add the Health to the Power type enum

Click on the Health Power up and choose the new Health Power-Up type

Next, we will code in the behaviour of what happens when the player touches the power-up and that is it is to add 1 life to the player by calling the Heal method in the Player script.

In the Player script, the Heal method adds one to the player lives if the lives are under three. It then calls a helper method, UpdateLiveUI to update the on-screen elements.

Refactoring has occurred to ensure showing the ship's damage works from both directions, adding damage, and removing the damage.

Let’s not forget to add this new power-up to the SpawnManager.

Now let’s play the game. In this example, the player gets hit by two lasers and picks up the power-up that you can see gives them an extra life, and removes one of the wing's damage.

If you enjoyed reading this article give me a Clap, also if you would like to see more, “Follow” me, so you may be notified of future releases. You may also send me a message if you need any further help.

--

--

Jean-Noel Seneque
Jean-Noel Seneque

Written by Jean-Noel Seneque

A Data & Analytics Consultant who is expanding into developing experiences in XR, Enterprise and Gaming space using Unity www.jeannoelseneque.com

No responses yet