public void SelectNextUnit(bool skipDoneUnits) { Player player = hexMap.CurrentPlayer; Unit[] units = player.Units; int currentIndex = 0; if (SelectedUnit != null) { for (int i = 0; i < units.Length; i++) { if (SelectedUnit == units[i]) { currentIndex = i; break; } } } for (int i = 0; i < units.Length; i++) { int tryIndex = (currentIndex + i + 1) % units.Length; if (skipDoneUnits == true && units[tryIndex].UnitWaitingForOrders() == false) { // Skip this unit continue; } // We only get here if we're on a valid pick SelectedUnit = units[tryIndex]; return; } // if we got here, selection did not change // If the pre-existing unit is done, and we're suppposed to skip that, // then clear the selection. if (SelectedUnit.UnitWaitingForOrders() == false && skipDoneUnits == true) { SelectedUnit = null; } }