/// <summary> /// /// </summary> /// <param name="cell"></param> /// <returns></returns> public IEnumerator MoveToCell(Cell cell) { if (!this.TurnOver) { if (!cell.Equals (this.Position ["LeftBottom"]) && _BaseMovementRangeNodes != null && _BaseMovementRangeNodes.Contains (Board.Instance.Graph [cell.X, cell.Y])) { Board.Instance.BaseMovementMode = true; Board.Instance.MovingMode = true; cell.ResetCellValues(); Node n = Board.Instance.Graph[cell.X, cell.Y]; List<Node> path = new List<Node> (); path.Add (n); path = FindWalkPath (n, path); path.Reverse (); TurnOffRangeIndicator (); foreach (string index in this.Position.Keys) { Cell c = this.Position [index]; Node node = Board.Instance.Graph [c.X, c.Y]; c.IsOccupied = false; c.GetComponent<MeshRenderer>().material.color = c.CellColor; } foreach (Node node in path) { yield return StartCoroutine (MoveNextTile (this.transform.position, new Vector3 (node.X, node.Y, this.gameObject.transform.position.z), 2f, n)); } CurrentMovement = n.H; this.SetNewPosition (Board.Instance.Graph [cell.X, cell.Y]); this.DeselectBase(); Board.Instance.MovingMode = false; Board.Instance.BaseMovementMode = false; GameController.Instance.IsDone(); } } }
/// <summary> /// This (unit) moves to a given cell. /// </summary> /// <param name="cell">The cell which the unit moves to.</param> /// <returns>Waits till the end frame.</returns> public IEnumerator MoveToCell(Cell cell, bool spawn) { Board.Instance.MovingMode = true; Debug.Log (Board.Instance.MovingMode); EndTurnPanel.Instance.EnableEndTurnButton (false); cell.ResetCellValues(); Node unitPosition = Board.Instance.Graph[Board.Instance.SelectedUnit.CellPosition.X, Board.Instance.SelectedUnit.CellPosition.Y]; Stack<Node> path; if (!spawn) { path = cell.SetPath(Board.Instance.Graph[cell.X, cell.Y], Board.Instance.Graph[unitPosition.X, unitPosition.Y], new Stack<Node>(), Board.Instance.Graph[cell.X, cell.Y].H); } else { List<Node> spawnPath = new List<Node>(); spawnPath.Add(Board.Instance.Graph[cell.X, cell.Y]); spawnPath = Board.Instance.SelectedBase.FindSpawnPath(Board.Instance.Graph[cell.X, cell.Y], spawnPath); path = new Stack<Node>(spawnPath); } _animator = this.GetComponent<Animator>(); _animator.Play("Walk"); _animator.speed = 2f; foreach (Node n in path) { PlaySound("Walk"); yield return StartCoroutine(MoveToNextNode(this.transform.position, new Vector3(n.X, n.Y, this.gameObject.transform.position.z), 2f, n)); } Board.Instance.SelectedUnit.CellPosition = cell; Board.Instance.SelectedUnit.CellPosition.IsInMovementRange = false; Board.Instance.SelectedUnit.CellPosition.PlacedUnit = this; cell.GetComponent<MeshRenderer>().material.color = Board.Instance.SelectedUnit.SelectionColor; cell.IsOccupied = true; _animator.Play("Idle"); EndTurnPanel.Instance.EnableEndTurnButton (true); if (!TurnOver) { if (!CheckEnemiesInAttackRange()) { UnitTurnIsOver(); this.DeselectUnit(); } } else { UnitTurnIsOver(); this.DeselectUnit(); } Board.Instance.MovingMode = false; GameController.Instance.IsDone(); }