This example shows how to use a MultiTargetPath using the Seeker::StartMultiTargetPath function.This script should be attached to any GameObject with children and a Seeker component.
This example is only valid when the pathsForAll parameter is set to true, if it is set to false, you can get the path info in the same way as a standard path.
- Version
- Tested in the A* Pathfinding Project 3.0.7
- A* Pro Feature:
- This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Pathfinding;
public class MultiTargetPathExample : MonoBehaviour {
#if FALSE
void Start () {
Seeker seeker = GetComponent<Seeker>();
seeker.pathCallback = OnPathComplete;
Vector3[] endPoints = new Vector3[transform.childCount];
int c = 0;
foreach (Transform child in transform) {
endPoints[c] = child.position;
c++;
}
seeker.StartMultiTargetPath (transform.position,endPoints,true);
}
public void OnPathComplete (Path p) {
Debug.Log ("Got Callback");
if (p.error) {
Debug.Log ("Ouch, the path returned an error\nError: "+p.errorLog);
return;
}
MultiTargetPath mp = p as MultiTargetPath;
if (mp == null) {
Debug.LogError ("The Path was no MultiTargetPath");
return;
}
List<Vector3>[] paths = mp.vectorPaths;
for (int i=0;i<paths.Length;i++) {
List<Vector3> path = paths[i];
if (path == null) {
Debug.Log ("Path number "+i+" could not be found");
continue;
}
for (int j=0;j<path.Count-1;j++) {
Debug.DrawLine (path[j],path[j+1],Mathfx.IntToColor (i,0.5F));
}
}
}
#endif
}