hello,
I’m working on a hex tile game that I want to be turn based. I’m using Unity5 beta and I’ve got pathfinding working as I want it and it’s using a point node graph.
I would like to get access to the nodes remaining in a path. I see in the debug log that it counts down the nodes as it moves towards its target (path Length)but I can’t figure out how to access it. I’m not that great a programmer :). Should I be looking at the debug section? Can anyone help please. bad bennet.
This is from my pathing agent:
`public void GetPath()
{
//GameObject.Find (“MapContents”).GetComponent ().Scan ();
targetPosition = target.transform.position;
//Get a reference to the Seeker component we added earlier
Seeker seeker = GetComponent<Seeker>();
//Start a new path to the targetPosition, return the result to the OnPathComplete function
seeker.StartPath(transform.position, targetPosition, OnPathComplete);
}
// Now that we have a path I can queue up the whole path and have it animate.
public void OnPathComplete(Path p)
{
Debug.Log("Yay, we got a path back. Did it have an error? " + p.error);
currentPath.Clear();
var allNodes = p.vectorPath;
List<Vector3> convertedCoords = new List<Vector3>();
foreach (Vector3 node in allNodes)
{
emptyObjectForConversion.transform.position = node;
Vector3 newCoord = emptyObjectForConversion.transform.localPosition;
currentPath.Add(_mapController.GetNodeAtPosition(newCoord));
currentPathPopulated = true;
}
foreach (RectTransform nodeToAdd in currentPath)
{
GlobalManager.Instance.gateLaneRenderer.AddZoneToPath(nodeToAdd);
}
}`
The important thing here is that the callback OnPathComplete(Path p) receives the path object as an argument. The path contains an array of all of the locations and you step through it yourself (generally anyway). Since you are stepping through the array yourself you already should know where you are in the array.
Hi Nakor, thanks very much for pointing me to this. Now I’ve got that int I was looking :).
Glad I could help