Adding Health Collectable in Unity

Objective: create a collectable that add one live to the player

To create the collectable I dropped the respective sprite in the scene and renamed the game object to “Health Collectable” and made it prefab.

Then I added the collider and rigidbody component to interact with the player.

After that I added the powerup script to the health collectable prefab and assigned the ID 4 (I used the powerup script because this collectable has the same behaviour than a powerup).

In the spawn manager object I added the health collectable prefab to the powerup array.

In the powerup script I added a new case for the ID 4 to call the function to add a live to the player.

In the player script I created a public function (the same function that we use in the powerup script) to add one live to the player.

Next in the player script I created a function called DrawEngines to check the current lives of the player and show/hide the engine damage according to the lives. This function is called each time the user loses or earns a life.

And good to go!!! The player recovers a life when take the new health collectible.

--

--

--

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

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

Recommended from Medium

Coin Toss Simulation.

4 Recommendations of Arduino Types for Beginners

Uno R3 DIP Arduino

Internationalize your app on the App Store in the blink of an eye!

How You Can Find Good Libraries For Your Projects

My First Day At OutBox

Codevember breakdowns Part 1 : Shadow Mapping

FinDAOra | Kucoin Tutorial 2/ Withdraw (from KuCoin to Findora Smart Chain)

Installing cf-for-k8s on Google Cloud GKE

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
Rusben Guzman

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

More from Medium

How To Upgrade Your Project to URP in Unity

Animating Sprites in Unity

Simple Player Movement in Unity

Adding Sound in Unity