Ok so I have an array of pathnodes, I need to select all of the pathnodes with the a specific zone ID and add them to the LocalPathNodeAR. But whenever I run the game it keeps giving me a null reference exception. I’m pretty sure its something to do with the LocalPathNodAR because thats where the debugging logs stop. Anyway heres the code, I hope someone can help me out here
var TEST;
static var PathTarget:GameObject;
public var AssignedZoneID:int;
var WorldPathNodeAR:GameObject[];
function Start () {
WorldPathNodeAR = GameObject.FindGameObjectsWithTag("PathNode");
FindPaths();
}
function FindPaths () {
var LocalPathNodeAR:GameObject[];
for(var g:GameObject in WorldPathNodeAR)
{
Debug.Log(WorldPathNodeAR.Length);
var pathNodeScript = g.GetComponent(PathNodeSetup);
if(pathNodeScript.PathZoneID == AssignedZoneID)
{
LocalPathNodeAR.Push(g);
}
}
Debug.Log(LocalPathNodeAR.Length);
var MyIndex = Random.Range(0,(LocalPathNodeAR.length - 1));
PathTarget = LocalPathNodeAR[MyIndex];
Debug.Log(LocalPathNodeAR);
}
function Update () {
this.GetComponent(NavMeshAgent).destination = PathTarget.transform.position;
var navmeshAgent = this.GetComponent(NavMeshAgent);
if(navmeshAgent.remainingDistance == 0)
{
FindPaths();
}
}