Categories

# Hello Every one, I was studding A* Algorithm and its is Showing nullObjectException n OnGizmos Function

I was studding A* Algorithm and its is Showing nullObjectException n OnGizmos Function when ever it complete Compiling the Code
here is my Code Can anybody Tell me what i am doing Wrong;

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace PathFinding {
public class Grid : MonoBehaviour {
public Transform Startpostion;
public Vector2 gridWorldSize;
public float Distance;

public Node[ , ] grid;
float NodeDiameter;
int GridSizeX, GridSizeY;
public List<Node> FinalPath;

private void Start () {
GridSizeX = Mathf.RoundToInt (gridWorldSize.x / 2);
GridSizeX = Mathf.RoundToInt (gridWorldSize.y / 2);
GridCreator ();

}
void GridCreator () {
grid = new Node[GridSizeX, GridSizeY];
Vector3 bottomLeft = transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.forward * gridWorldSize.y / 2;
for (int y = 0; y < GridSizeY; y++) {
for (int i = 0; i < GridSizeX; i++) {
Vector3 WorldPositionOfCurrentNode = bottomLeft + Vector3.right * (i * NodeDiameter + nodeRadius) + Vector3.forward * (y * NodeDiameter + nodeRadius);
bool Wall = true;

Wall = false;
}
grid[i, y] = new Node (Wall, WorldPositionOfCurrentNode, i, y);
}
}
}
private void OnDrawGizmos () {
Gizmos.DrawWireCube (transform.position, new Vector3 (gridWorldSize.x, 1, gridWorldSize.y));

foreach (Node n in grid) {
if (n.is_Wall) {
Gizmos.color = Color.white;
} else {
Gizmos.color = Color.yellow;
}
if (FinalPath != null) {
if (FinalPath.Contains (n)) {
Gizmos.color = Color.red;
}
}
Gizmos.DrawCube (n.postion, Vector3.one * (NodeDiameter - Distance));
}
}
}
}
``````