- Home /
Player Respawn After Death
I have the player dieing when health is equal to 0 using C#, but I am not sure how to have them respawn at a spawnpoint.
Thanks
Answer by Justin Warner · Dec 22, 2010 at 05:22 AM
Find the player (Use the tag system to do so), if it is null, than instantiate the player prefab at _ location. =) Their's psuedo code =).
I'm still having issues getting an instance to respawn. Below is the code that I'm using. Any thoughts?
public class HealthSphere : $$anonymous$$onoBehaviour { public int maxHealth = 100; public int Health = 100; public Transform PlayerPrefab;
void Update () {
if(curHealth <= 0)
Destroy(GameObject.FindGameObjectWithTag("Player"));
/*if(GameObject.FindGameObjectWithTag("Player") == null)
Instantiate(PlayerPrefab, GameObject.Find("PlayerSpawnPoint").transform.position, Quaternion.identity);
Health = maxHealth;
}
Sorry man, I wish I could help, I don't know C, I only know Java, I also know their isn't much of a difference, I just don't like not knowing what is their. Post in a new question, many can help =).
It took a little fiddling, had to return health to zero first, but its working! thanks