Day 90: Player Lives Part 2
Objective: Cause damage to the player.
Today we will allow the player to lose lives when they fall off the platforms. The first thing we will do is create a cube game object and position it where you would like the player to die.
This will need a Box Collider with IsTrigger set to true. A Rigidbody with gravity turned off. We will also turn off the Meshrenderer on the Game Object.
Now we will create a script called Dead Zone. Inside this new script we will use OnTriggerEnter(){}. Inside the OnTriggerEnter, we will check to see what entered the trigger. If it is the player we will grab the player script from the player object. If the player script was not null, we will call the Damage method that we created in yesterday’s article.
This will hurt the player and then kill them if the health is zero.
Tomorrow we will update the UI to show the amount of lives. Thank you for reading and have a wonderful day!!