public void MoveUnit() { AttackUnit = null; if (path.Count == 0) { return; } List <HexCell> move = new List <HexCell>(); move.Add(path[0]); int cellNumber = 1; while (movementLeft > 0 && path.Count > 1) { if (path.Count > cellNumber) { int movementCost = HexUnit.GetMoveCost(path[cellNumber - 1], path[cellNumber], path[cellNumber - 1].GetNeighborDirection(path[cellNumber]), true); if (movementCost == -1 || movementCost > movementLeft) { break; } else { move.Add(path[cellNumber]); movementLeft -= movementCost; cellNumber++; } } else { break; } } if (move.Count > 1) { AttackUnit = null; AttackCity = null; City city = move[move.Count - 1].City; if (city && hexUnit.HexUnitType == HexUnit.UnitType.COMBAT && GetCityState() != city.GetCityState()) { AttackCity = city; CombatSystem.CityFight(this, city); SetMovementLeft(0); } else { HexUnit unitToFight = move[move.Count - 1].GetFightableUnit(HexUnit); if (unitToFight) { AttackUnit = unitToFight; CombatSystem.UnitFight(this, unitToFight.GetComponent <Unit>()); SetMovementLeft(0); } } path.RemoveRange(0, move.Count - 1); HexUnit.Travel(move); } }