Help with Respawning player

Hey! So I’m making a game inspired by Takeshi’s Castle. So there’s also a lives system in it. And so when the player dies, it reduces one life from it but the real problem is when the player dies by falling off the edge or any casualaties I want the player to respawn at the point where it was about to fall.

Like if the player falls down and dies, I want the player to respawn at the same ledge from where it died the last time.

[Read my Previous Reply First]

This Code is for the first collider (just duplicate and change the value of ColliderNum for others):

public class Collider1 : MonoBehaviour {

void OnTriggerEnter (Collider Player) {
	if (Player.tag == "Player") {
		PlayerPrefs.SetInt("ColliderNum", 1);


This Code is what will handle it:

public class CodeHandler : MonoBehaviour {

private int ColliderNum; 

private float x_Pos;
private float y_Pos;
private float z_Pos;

void Update() {
	ColliderNum = PlayerPrefs.GetInt("ColliderNum", 0); //Gets the ID of the collider where 
												       //the Player collided and could die.
	if (ColliderNum == 1) {
		x_Pos = x; //Values that I told you to write
		y_Pos = y; //on Paper at Places where the Player
		z_Pos = z; //could die.
	if (ColliderNum == 2) {
		x_Pos = x2;
		y_Pos = y2;
		z_Pos = z2;


You can add the following code to your MainScript:

public class PlayerHandler : MonoBehaviour {

public CodeHandler myScript; //Accesses the Script.
public GameObject myPlayer; //The Player.

private float pos_X;
private float pos_Y;
private float pos_Z;

void Update() {
	pos_X = myScript.x_Pos;
	pos_Y = myScript.y_Pos;
	pos_Z = myScript.z_Pos;

public void Death() { //Your Death Function, just Update it.
	Player.transform.position = new Vector3(pos_X, pos_Y, pos_Z);


Try to get and store the position of the player when he is on an edge/place where he may fall… Like temporary coordinates. Update these values when he change places. Then if he dies, respawn him at the temporary coordinates stored. Take a look at Vector3 in the documentation.