IEnumerator DeathCoroutine() { Debug.Log(gameObject.name + " has died"); if (gameObject.name == treasureCache.hasTreasure) { treasureCache.hasTreasure = "none"; treasureCache.MoveTreasure2Dead(); } Move2p moveCache = gameObject.GetComponent <Move2p> (); BoxCollider boxy = gameObject.GetComponent <BoxCollider> (); foreach (GameObject obj in playerDisableOnDeath) { obj.SetActive(false); } moveCache.enabled = false; boxy.enabled = false; RemoveArrows(); Vector3 v3Current = new Vector3(0, 0, 0); v3Current = transform.eulerAngles; Quaternion qRotation = Quaternion.identity; qRotation.eulerAngles = v3Current; Instantiate(deathRagdoll, transform.position, qRotation); health = maxHealth; while (playerRespawnTime > 0) { yield return(new WaitForSeconds(1)); playerRespawnTime--; Debug.Log(gameObject.name + " time to respawn " + playerRespawnTime); } if (playerRespawnTime <= 0) { Transform rndSpwn = reCache.PlayerRandomSpawn().transform; transform.position = rndSpwn.position; foreach (GameObject obj in playerDisableOnDeath) { obj.SetActive(true); } boxy.enabled = true; moveCache.enabled = true; moveCache.UpdateTreasure(false); playerRespawnTime = maxPlayerRespawnTime; } }