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

Securely using secrets in a pipeline — HashiCorp Vault + JWT Auth

The irony of software engineering

Predict the Rise of GameStop ($GME) in Less Than 20 Lines of Code

Image of person holding phone with laptop in background.

Chinese Year Of The Ox Aleph.im Node Operators Bonus

4 Recommendations of Arduino Types for Beginners

Uno R3 DIP Arduino

EdgeMultiplay (Unity Multiplayer Solution)

Genetic algorithm vs. Backtracking: N-Queen Problem

CS 373 Fall 2021: Gregory Raper Week 11

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

Creating A Modular Powerup System in Unity

Editing Texture Maps

Galaxy Shooter —Basic Enemy AI

First! Unity.