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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Custom Button with Shadow in Android

build.gradle: The source file I used to neglect

Android Dialogflow Chatbot Library

Funimation APK v3.7.0

Phase 2: PowerUps Destroyed by the Enemy

Media3 ExoPlayer in Jetpack Compose to make Snapchat Spotlight

Whats new in Jetpack 2021 Google I/O 2021

How to Integrate Firebase Crashlytics to Android project in Android studio

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Bill Rislov

Bill Rislov

Unity / C# Game developer

More from Medium

Mastering Unity Scripting | Summary — Chapter 2: Debugging

Point & Click to Move in Unity

Did you just hit me! — Hitbox attack system in Unity2D

Creating An Advanced 2D Player Controller Without Any Unity Components! (Part 1)