- Unity 2018 Artificial Intelligence Cookbook(Second Edition)
- Jorge Palacios
- 116字
- 2021-07-16 18:11:26
There's more...
It's important to take into account the order in which the nodes are linked in the inspector for the path to work as expected. A practical way to achieve this is to manually name the nodes with a reference number:

An example of a path set up in the Inspector window
Also, we could define the OnDrawGizmos function in order to have a better visual reference of the path:
void OnDrawGizmos () { Vector3 direction; Color tmp = Gizmos.color; Gizmos.color = Color.magenta;//example color int i; for (i = 0; i < nodes.Count - 1; i++) { Vector3 src = nodes[i].transform.position; Vector3 dst = nodes[i+1].transform.position; direction = dst - src; Gizmos.DrawRay(src, direction); } Gizmos.color = tmp; }