// Death is called when the unit dies // sets flags and does logistic clean up public IEnumerator Death() { // stop drawing the unit sprite gameObject.GetComponent <SpriteRenderer>().enabled = false; // set the dead flag to true dead = true; // remove the unit from the unitList in the level manager levelManagerScript.unitList.Remove(gameObject); // before destroying the unit, wait for a combat it may be a part of to end yield return(new WaitWhile(() => experienceUpdating)); // check if this triggers a level end levelManagerScript.CheckLevelEnd(); // run finish action to check if the phase should end FinishAction(); // unit is no longer an occupyingObject on the tile tileCur.GetComponent <TileScript>().occupyingObject = null; // destroy the gameObject Destroy(gameObject); }