public void Update() { if (delayTime <= 0 && !moving) { if (aiTurn && toActAI.Count == 0) { selectionState = State.EnemyTurn; foreach (Unit unit in aiUnits) toActAI.Enqueue(unit); if (toActAI.Count == 0) { moving = true; UIManager.getUIManager().clearDisplay(); pathFinder.clearRangeDisplay(); return; } } if (aiTurn) { currentAIUnit = toActAI.Dequeue(); UIManager.getUIManager().setDisplayedUnit(currentAIUnit); pathFinder.displayRangeOfUnit(currentAIUnit, currentAIUnit.getNode().getPos()); currentAction = ai.RunAI(currentAIUnit, playerUnits); UIManager.getUIManager().setDisplayedUnit(currentAIUnit); lockMovement(); currentAction.Move(finishedMoveCallbackAI); } if (!aiTurn && toActAI.Count == 0) { selectionState = State.EnemyTurn; foreach (Unit unit in playerUnits) toActAI.Enqueue(unit); if (toActAI.Count == 0) { moving = true; UIManager.getUIManager().clearDisplay(); pathFinder.clearRangeDisplay(); return; } } if (!aiTurn) { currentAIUnit = toActAI.Dequeue(); UIManager.getUIManager().setDisplayedUnit(currentAIUnit); pathFinder.displayRangeOfUnit(currentAIUnit, currentAIUnit.getNode().getPos()); currentAction = ai.RunAI(currentAIUnit, aiUnits); UIManager.getUIManager().setDisplayedUnit(currentAIUnit); lockMovement(); currentAction.Move(finishedMoveCallbackAI); } else { selectionState = State.OurTurnNoSelection; if (Input.GetMouseButtonDown((int)MouseButton.left)) { Vector2 position = getMousePos(); if (positionInGraph(position)) { Node clickedNode = pathFinder.closestMostValidNode(position); if (unitSelected) { currentlySelectedUnit.deselect(); unitSelected = false; selectionState = State.OurTurnNoSelection; } if (clickedNode.Occupied) { currentlySelectedUnit = clickedNode.Occupier; currentlySelectedUnit.select(); unitSelected = true; pathFinder.displayRangeOfUnit(currentlySelectedUnit, position); if (currentlySelectedUnit.isEnemy()) selectionState = State.UnitActed; else selectionState = State.UnitFresh; } else { pathFinder.clearRangeDisplay(); selectionState = State.OurTurnNoSelection; } } } if (Input.GetMouseButtonDown((int)MouseButton.right)) { pathFinder.clearRangeDisplay(); selectionState = State.OurTurnNoSelection; } } } else { // disables all buttons while locked selectionState = State.EnemyTurn; if (delayTime > 0) delayTime--; } UIManager.getUIManager().ChangeButtonState(selectionState); }