Player Reaspawn Script

Hello, I’m trying to make a script for my player that will make him respawn when his health bar hits 0. i have the health bar all set up but i can’t figure out how to make a respawn script, or add a respawn function to my player health script, so here is what i have so far:

     // Reset Player After health is at 0
		if(PlayerHealth = 0) {
			Respawn(Target);
			
		}

Thanks!

fairly simple… First, you need respawn points. Emtpy game objects littered throughout your map all with the tag “SpawnPoint”

next, you need to fulfil the “Respawn(Target)” function:

function Respawn(object : GameObject){
	var respawnPoints=GameObject.FindGameObjectsWithTag("SpawnPoint");
	var respawnPoint=respawnPoints[Random.value * respawnPoints.Length];
	object.transform.position=respawnPoint.transform.position;
	object.transform.rotation=Quaternion.identity;
	object.transform.localEulerAngles.y=Random.value * 360;
}

Some documentation:

You’d have to be a little more clear as to the type of game and how you want the player respawn. You could use Application.LoadLevel(), but that would reset everything in your scene. That’s good for puzzle type games, but since I’m assuming action, you can have an array of spawn locations, find the closest one, and teleport your player there for a respawn.

Alright, thanks everyone!