I’ve created a waypoint script that is attached to a player where the Spawn point changes when a player hits a trigger and that works fine. The problem I’m running into is creating a certain time for a player to respawn. I’ve created a coroutine that yields for a few seconds but that isn’t working. Can anybody help me with this simple problem?
using UnityEngine;
using System.Collections;
public class Waypoint : MonoBehaviour {
public Vector3 Pos = new Vector3(89.83092f,-167.0952f,342.0801f);
void OnTriggerExit (Collider playerCollision)
{
if (playerCollision.CompareTag("trap"))
{
StartCoroutine( Coundowndeath());
gameObject.transform.position = Pos;
}
else if (playerCollision.CompareTag("Checkpoint1"))
{
Pos = playerCollision.transform.position;
}
else if (playerCollision.CompareTag("Checkpoint2"))
{
Pos = playerCollision.transform.position;
}
}
IEnumerator Coundowndeath()
{
yield return new WaitForSeconds(2f);
}
void Start () {
}
}