How to do it...

Even though this recipe is only for defining a function, please take into consideration the comments in the code for a better understanding of the implementation and code flow:

  1. Modify the Graph class and add a couple of member variables, one for storing the path and the other for knowing whether the coroutine has finished:
public List<Vertex> path; 
public bool isFinished; 
  1. Declare the member function:
public IEnumerator GetPathInFrames(GameObject srcObj, GameObject dstObj, Heuristic h = null) 
{ 
    //next steps 
} 
  1. Include the following member variables at the beginning:
isFinished = false; 
path = new List<Vertex>(); 
if (srcObj == null || dstObj == null) 
{ 
    path = new List<Vertex>(); 
    isFinished = true; 
    yield break; 
} 
  1. Modify ...

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.