IEnumerator AdvanceTurn() { controlLocked = true; activeUnit.EndTurn(); roundCounter--; if (roundCounter <= 0) { UpdateEnvironmentalHazards(); roundCounter = currentUnits.Count; } //Let effects run their course before setting enemy loose. yield return(new WaitForSeconds(turnDelay)); //Updates pathfinding based on current unit positions. UpdateUnwalkables(); //Updates the turn order ui. activeUnit = currentUnits.Dequeue(); //Moves the unit to the back of the queue. currentUnits.Enqueue(activeUnit); //Next up in line goes. activeUnit = currentUnits.Peek(); if (activeUnit.dead) { RemoveUnit(currentUnits.Dequeue()); activeUnit = currentUnits.Peek(); } activeUnit.StartTurn(); UIManager.Instance.UpdateTurnOrderPortraits(currentUnits); if (activeUnit.IsNpc) { yield return(StartCoroutine(EnemyTurn())); yield return(new WaitForSeconds(turnDelay)); StartCoroutine(AdvanceTurn()); } else { UIManager.Instance.UpdateActiveUnitAbilities(activeUnit); } controlLocked = false; }