Day 89: Player Lives Part 1

Tyler Smallwood
3 min readNov 15, 2021

--

Photo by Sigmund on Unsplash

Objective: Create a system to re-spawn the player.

This and the next article will cover the basic’s of the players lives system. Today will be implementing lives and allow the player to get damaged.

For our lives, we need to have a variable to track it.

Now we will create a method that will remove live when a player gets hit or falls off the map. We will call it Damage.

When ever this method gets call we will subtract one life. We will just use _lives — ;

After we subtract a life, we will need to check to see if the lives are less than or equal to zero. If it is less than 0 we will restart the scene by using SceneManager.LoadScene();. If it is not less than zero, we will turn off the CharacterController. We will then assign the players position to a respawn point.

After the if statement we will than re-enable the CharacterController so the player will be able to move again.

The UIManager will be discussed in tomorrows article to explain the process or updating the UI for Lives. We will cover the SceneManager real quick. To use the SceneManager, we will use the using statement SceneManagement.

We will set up the Build Settings to assign the scene.

Before finishing we will need to set up the respawn point. We will create a empty gameobject and just align it to the start of the game for now.

Now in the player script we will get a variable to hold the respawn point.

Now just drag the respawn point to the player script on the player object.

Now with that done, our player can jump off the edge of the map and respawn.

Thank you for reading and have a wonderful day.

--

--

Tyler Smallwood
Tyler Smallwood

Written by Tyler Smallwood

I am passonate on learning to program and use Unity to become a skillful Unity Developer

No responses yet