public IEnumerator FindPath(Vector3 startpos, Vector3 targetpos) { Node StartNode = grid.NodeFromWorldPoint(startpos); Node TargetNode = grid.NodeFromWorldPoint(targetpos); waypoints = new Vector3[0]; bool pathsuccess = false; if (StartNode.walkable && TargetNode.walkable) { Heap <Node> OpenSet = new Heap <Node>(grid.MaxSize); HashSet <Node> ClosedSet = new HashSet <Node>(); OpenSet.Add(StartNode); while (OpenSet.Count > 0) { Node CurrentNode = OpenSet.RemoveFirst(); ClosedSet.Add(CurrentNode); CurrentNode.gm.GetComponent <SpriteRenderer>().color = Color.green; CurrentNode.text.text = CurrentNode.F_Cost.ToString(); if (CurrentNode == TargetNode) { pathsuccess = true; // TracePath(StartNode,TargetNode); break; } foreach (Node neighbour in grid.GetNeighbours(CurrentNode)) { if (!(neighbour.walkable) || ClosedSet.Contains(neighbour)) { continue; } int NewMovementcosttoNeighbour = CurrentNode.G_Cost + GetDistance(CurrentNode, neighbour); if (NewMovementcosttoNeighbour < neighbour.G_Cost || !OpenSet.Contains(neighbour)) { neighbour.G_Cost = NewMovementcosttoNeighbour; neighbour.H_Cost = GetDistance(neighbour, TargetNode); neighbour.Parent = CurrentNode; neighbour.text.text = neighbour.F_Cost.ToString(); if (!OpenSet.Contains(neighbour)) { neighbour.gm.GetComponent <SpriteRenderer>().color = Color.red; OpenSet.Add(neighbour); } else { OpenSet.UpdateItem(neighbour); neighbour.text.text = neighbour.F_Cost.ToString(); } } // yield return new WaitForSeconds(2f); } // yield return new WaitForSeconds(.5f); } } yield return(null); if (pathsuccess) { waypoints = TracePath(StartNode, TargetNode); // drawpath(); print("okey path found"); } else { print("hey bitch no path"); } // print("waypoints"+waypoints.Length); pathRequestManager.FinishedProcessingUnit(waypoints, pathsuccess); }