IEnumerator _OnEndTurn() { yield return(null); if (GetMoveOrder() == _MoveOrder.Free) { unitSwitchingLocked = false; } if (instance.turnMode == _TurnMode.FactionAllUnitPerTurn) { if (GetMoveOrder() == _MoveOrder.Free) { MoveToNextTurn(); } else { if (!UnitControl.AllUnitInFactionMoved(turnID)) { UnitControl.OnNextUnit(); } else { MoveToNextTurn(); } } } else if (instance.turnMode == _TurnMode.FactionSingleUnitPerTurnSingle) { MoveToNextTurn(); } else if (instance.turnMode == _TurnMode.FactionSingleUnitPerTurnAll) { if (UnitControl.AllUnitInAllFactionMoved()) { GridManager.Deselect(); ResetTurnID(); OnNewRound(); } else { //first check if all the unit has been moved, if yes, switch to next faction NextTurnID(); if (turnID >= totalFactionInGame) { turnID = 0; } int counter = 0; while (UnitControl.AllUnitInFactionMoved(turnID)) { NextTurnID(); if (turnID >= totalFactionInGame) { turnID = 0; } //if all the faction has been looped through if ((counter += 1) > totalFactionInGame) { Debug.Log("error, no available faction"); //return; yield break; } } //UnitControl.OnNextUnit(); instance.StartCoroutine(instance.OnNextTurn()); } } else if (instance.turnMode == _TurnMode.SingleUnitPerTurn) { instance.StartCoroutine(instance.OnNextTurn()); } else if (instance.turnMode == _TurnMode.SingleUnitRealTime || instance.turnMode == _TurnMode.SingleUnitRealTimeNoRound) { instance.StartCoroutine(instance.OnNextTurn()); } }