Hello everyone, I am having a bit of a problem here. I have a script to respawn the player in my game after he dies, and It works, but when I die It spawn 2 players, then 3 then 4 and so on, and this obviously causes problems, so how do I fix this problem? Here is my code (the respawning part anyway)
function OnTriggerEnter (hit : Collider)
{
if (hit.gameObject.tag == "Hostile")
{
Destroy(hit.gameObject);
Destroy(gameObject);
dead = true;
}
if(dead)
{
Instantiate(playerPrefab, gameObject.FindWithTag("Respawn").transform.position, Quaternion.identity);
}
}