If the Player falls off the platform, how do we deduct life and respawn it in a set position?
First, you need to specify a set position where the Player will spawn:
Next, we need to specify a dead zone where if the Player touches this boundary, we will deduct a life and place it to the spawn position again:
On my end, it’s just a stretched cube without a mesh with trigger enabled and DeadZone script to handle the condition.
On the Player we add public Damage() method to deduct life and if life is less than 1, we will reload the scene:
On the DeadZone we detect if the Player is the one who collided with the Dead_Zone object, deduct life and place it back to the spawn position:
Note the part where the character controller is disabled before changing the position of the Player. This is needed because if the Player falls too fast, it’s not able to spawn at the desired position.
Now, spawning and reloading the scene when Player’s life is less than 0 works: