Having problems with adding a delay in my during respawn after the player dies.
Below, the ONTRIGGER does what I want it to. When my player gets hit my Life Counter subtracts 1, my explosion spawns, and my player respawns at its spawnpoint and I run through the IFrames CoRoutine for my invulnerability for three seconds and back to normal.
The problem I run into is trying to delay that respawn. I want to have a second or two between the explosion and respawn to give the player a short break to regroup. I’ve searched a bit and found that I can use a Coroutine for a delay which I implemented here but it doesn’t seem to do anything.
I’ve placed this Delay() in RespawnPlayer before the spawn and it does nothing. I have a Yield…WaitForSeconds() in my Invulnerability CoRoutine and it works just fine. Am I overlooking something simple here?
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Enemy") || other.CompareTag("Ground"))
{
lifeSystem.TakeLife();
Pooler.Spawn(explosion, this.transform.position, this.transform.rotation);
RespawnPlayer();
}
}
public void RespawnPlayer()
{
StartCoroutine(Delay());
this.transform.position = spawnPoint.position;
StartCoroutine(GetInvulnerable());
}
IEnumerator Delay()
{
yield return new WaitForSeconds (2f);
}