Hey everyone. Can someone help me poiting some errors in this Pathfinding function?

This is just breaking Unity.

```
void AStar (Node initialNode, Node finalNode) {
openList = closedList = new List<Node>();
initialNode.G = 0;
initialNode.H = initialNode.GetH( finalNode );
openList.Add(initialNode);
Node current = null;
while(openList.Count != 0) {
current = openList[0];
closedList.Add(current);
if(current == finalNode) {
reconstructPath(openList);
return;
}
foreach(Node neighbor in current.Neighbors) {
if(closedList.Contains(neighbor)) {
continue;
} else {
if(!openList.Contains(neighbor)) {
neighbor.defineParentNode(current);
neighbor.GetF(current, finalNode);
openList.Add(neighbor);
} else {
int neighborG = neighbor.GetG(current);
if(neighborG < neighbor.G) {
neighbor.defineParentNode(current);
neighbor.G = neighborG;
}
}
}
}
openList.Sort(delegate(Node x, Node y) {
return x.F.CompareTo(y.F);
});
}
}
```

And here’s the Node class :

```
public class Node {
public Vector3 position;
public List<Node> Neighbors; // these are defined with a function that I omitted, but I'm sure that it doesn't return a empty list
public Node parentNode;
public int F, G, H;
public Node (Vector3 Position, bool DefineNeighbors) {
position = Position;
}
public int GetF (Node currentNode, Node finalNode) {
this.G = GetG(currentNode);
this.H = GetH(finalNode);
this.F = this.G + this.H;
return this.F;
}
public int GetH (Node finalNode) {
H = (int)(Mathf.Abs(this.position.x - finalNode.position.x) + Mathf.Abs(this.position.z + finalNode.position.z));
return H;
}
public int GetG (Node currentNode) {
int distanceToCurrent = (int)(Mathf.Abs(this.position.x - currentNode.position.x) + Mathf.Abs(this.position.z + currentNode.position.z));
G = currentNode.G + distanceToCurrent;
return G;
}
public void defineParentNode(Node parent) {
this.parentNode = parent;
}
}
```

If someone have the time to read the code and point something that could be make me get stuck in the loop, I’ll appreciate!

Thanks from now!