/// <summary> /// Tells the unit to follow the specified path. /// </summary> /// <param name="path">The path to be followed by this unit</param> public HexDirection TravelPath(List <BattleHex> path) { if (path.Count == 1) { return(_facingDirection); } float currentRotation = Mathf.Round(base.transform.eulerAngles.y); Vector3 startPosition = Vector3.zero; Vector3 endPosition = this.CurrentHexTile.WorldPosition; HexDirection facingDirection = _facingDirection; for (var i = 0; i < path.Count - 1; i++) { BattleHex current = path[i]; BattleHex next = path[i + 1]; HexDirection requiredDirection = HexHelpers.GetTargetDirection(current, next); float requiredRotation = HexHelpers.GetTargetDegrees(requiredDirection); if (i == 0 && currentRotation != requiredRotation) { _actions.Enqueue(new UnitRotation(this, currentRotation, requiredRotation)); currentRotation = requiredRotation; facingDirection = requiredDirection; } float distance = current.TileLength; float speedModifier = 1f; if (i == 0) { distance /= 2f; speedModifier = 2f; } startPosition = endPosition; endPosition = next.GetEdge(requiredDirection); HexDirection requiredFacingDirection = HexHelpers.ReverseDirection(requiredDirection); _actions.Enqueue(new UnitMovement(this, startPosition, endPosition, current, facingDirection, requiredFacingDirection, currentRotation, requiredRotation, speedModifier)); facingDirection = requiredFacingDirection; currentRotation = requiredRotation; } BattleHex endTile = path[path.Count - 1]; _actions.Enqueue(new UnitMovement(this, endPosition, endTile.transform.position, endTile, facingDirection, facingDirection, 0f, 0f, 2f)); this._currentAction = this._actions.Dequeue(); _battleGrid.UnhighlightNodes(); return(facingDirection); }