I am trying to add a delay to the respawn of my player. But when I add the yield return new line nothing runs after it. I have tried addiing debug.log after everyline and they stop out putting once they get to the yield return new line. This respawn is on the player on its own script and there is no other script that would effect the player respawn. The game is also 2D. Here is the code
public GameObject spawnPoint;
public float respawnDelay = 2;
public IEnumerator RespawnPlayer()
{
gameObject.SetActive(false);
gameObject.transform.position = spawnPoint.transform.position;
yield return new WaitForSeconds(respawnDelay);
gameObject.SetActive(true);
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "Enemy")
{
StartCoroutine(RespawnPlayer());
}
}
Thanks!
other.compareTag(“Enemy”)
instead ofother.gameObject.tag == "Enemy"
. See: docs.unity3d.com/ScriptReference/Component.CompareTag.html \$\endgroup\$