Function Path.WaitForPath
Waits until this path has been calculated and returned.
IEnumerator WaitForPath ()
Waits until this path has been calculated and returned.
Allows for very easy scripting.
IEnumerator Start () {
// Get the seeker component attached to this GameObject
var seeker = GetComponent<Seeker>();
var path = seeker.StartPath(transform.position, transform.position + Vector3.forward * 10, null);
// Wait... This may take a frame or two depending on how complex the path is
// The rest of the game will continue to run while we wait
yield return StartCoroutine(path.WaitForPath());
// The path is calculated now
// Draw the path in the scene view for 10 seconds
for (int i = 0; i < path.vectorPath.Count - 1; i++) {
Debug.DrawLine(path.vectorPath[i], path.vectorPath[i+1], Color.red, 10);
}
}
Do not confuse this with AstarPath.BlockUntilCalculated. This one will wait using yield until it has been calculated while AstarPath.BlockUntilCalculated will halt all operations until the path has been calculated.