protected IEnumerator PathfindThenTakeTurn(NavNode destination) { //Wait for pathfinder to finish its search. _pathfinder.Search(_node, destination); while (_pathfinder.Running) { yield return(null); } if (_pathfinder.PathStatus == PathStatus.success) { List <NavNode> path = _pathfinder.GetPath(); //0 is our current position, so position 1 is the next. if (path.Count > 1) { NavNode next = path[1]; Vector3Int dir = next.cellPos - _node.cellPos; Move m = new Move(puzzleManager, false); m.AddAgentToMove(this, dir, true, null, null, 50); puzzleManager.ExecuteAICommand(m); if (m.IsValid) { puzzleManager.HoldPlayerForAI(this); } } } }
/// <summary> /// Coroutine to search for the destination, simply waiting until destination is found. /// </summary> private IEnumerator FindPathToDestination(NavNode final) { _pathfinder.Search(_player.CurrentNode, final); //Wait for pathfinder to finish its search. while (_pathfinder.Running) { yield return(null); } if (_pathfinder.PathStatus == PathStatus.success) { _moveChainCoroutine = StartCoroutine(MoveToDestination(_pathfinder.GetPath())); } }