- Home /
Respawn Player Using a Coroutine
Hello there, I'm attempting to respawn my player character by detecting for a collision, and then running a coroutine that destroys the current player, and then instantiates a new player prefab at a public spawn point.
Problem is... (drumroll)... it doesn's work.
public Transform spawnPoint;
public GameObject currentPlayer;
public GameObject newPlayer;
void OnCollisionExit(Collider Ragdoll){
{
StartCoroutine(DieAndRespawn());
}
}
IEnumerator DieAndRespawn() {
Destroy(currentPlayer);
yield return new WaitForSeconds(2.0f);
Instantiate (newPlayer, spawnPoint.position, Quaternion.identity);
}
I'm using a coroutine to add a few seconds before the player spawns. I've tried a number of options before landing on a coroutine, which seems like the best way to go. My intuition is telling me I'm missing something simple; any help is appreciated.
Could you be a little more specific, you're telling us it doesn't work but what does it do ? Does your player respawn instantly ? or do you lost the reference to your player ?
Your answer
Follow this Question
Related Questions
Instantiate creates endless clones and disables collider 1 Answer
OnTrigger Stay/Exit - Stay Overriding Exit 2 Answers
Coroutine not working correctly? 1 Answer
How to wait for Start() to run when calling InstantiateObject() 1 Answer
Only 1 of 3 conditions being executed in IF statement?(Solved) 1 Answer