2.5D Platformer — #6 Lives and Respawning

This platformer is now ready to have player lives introduced. A player with lives must have something to remove the lives and for this, we will add a kill zone at the bottom that span the whole level. We need text on the screen to display the number of lives the player currently has and if the player has no more lives, restart the game.

First, let's create a variable to store the number of lives

Let’s add UI TextMeshPro to display the lives

Let's create a cube, rename to Killzone and span it the whole level and position it at the bottom. Turn off the Mesh Render and check Is Trigger. Create a Tag and call it Killzone and set the Killzone as Killzone tag.

In the Player script, create OnTriggerEnter. Here we detect if we have touched the Killzone, reduce life and trigger an event similar to the CoinsCollected. If the life is zero, restart the game otherwise, respawn.

Change the UI Manager to subscribe to the event and update the UI.

Drag the LiveText to the UI Manager reference

Finally, we will need a Spawn Point, create an empty and name it Spawn Point.

Create a reference to it and drag the Spawn Point onto the Player script on the Player

Make sure the current scene is in the Build scenes as index 0.

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.

Do you have a project in mind that you need help with, I’m available!

--

--

--

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

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

Recommended from Medium

Now in Android #47

Jetpack Compose Ep:6 — Floating Action Button App

How we redesigned LCL Mes Comptes on Android

Home screen Widget for an Android App

Paging 3 — Easier Way to Pagination

Remove Android Compile Time Permission in Flutter app

Android’s strings.xml: Deprecated!

How it can be done? Image downloading on pure threads.

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
Jean-Noel Seneque

Jean-Noel Seneque

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

More from Medium

Working with Unity’s 2D Tilemaps

How to Install the Universal Render Pipeline

Adding a burst laser powerup

Indy Pro ’22: IWTV