Respawning my AVATAR

Hi there,
I have a script spawning my player at the beginning of the game.

When my player dies ( when falling from more than 8 meters ).

My respawn is not working.

Any idea to help me ?

Thank you…

Here is my script:

public class DeathRecognition : MonoBehaviour

{

public Transform spawnPoint;

public bool falling = false; 
public float lastY;    		// last grounded height
public float hauteurChute;	//	ce ki cause ma mort
public CharacterController  character;	//	sera eventuellement detruit
private float deathFall = 7.632f;	// pour etre constant de mon 8 m de map...
									// lavatar glisse un peu sur les parois (+/- 0.30)

void spawn()
{		
	transform.position = spawnPoint.position;
}
void Start()
{
	spawn();
}


void Update()
{
	
	if (character.isGrounded == false)	// est en train de tomber sans avoir saute
	{
		hauteurChute = lastY - transform.position.y ;
		if (hauteurChute < 0) lastY = this.transform.position.y;	//	si je suis en train de sauter
																	//	la valeur la + haute de mon saut
	}
	else 
	{
		if ( hauteurChute > 0.5 )
		{
			Debug.Log("Hauteur du saut :"+ hauteurChute);	//	hauteur de mon saut
		}
		
		if ( hauteurChute >= deathFall )
		{
			Debug.Log("DEAD");
			Die();
			
		}
		hauteurChute = 0.0f;				//	si ma chute n<est pas mortelle
		lastY = this.transform.position.y;	//	je reinitialise ma chute a 0
	}
}


void Die()
{
	Destroy(gameObject);
	spawn();
}

}

Basically, the problem is here:

void Die()
{
    Destroy(gameObject);
    spawn();
}

This will first destroy the object, and then call ‘spawn’ which moves the transform back to the spawnPoint.

However, because the object gets destroyed first, it won’t work! The object gets moved to the spawn point, and then disappears before the next frame begins.

If you just want the player to move back to the spawn, remove the ‘Destroy’ line.

If you want it to create a new player after destroying the old one, try instantiating a prefab, or in fact calling

Instantiate(gameObject);

which will create a perfect copy of the character.