Hello there! I have been making a game on Mazes. For this I have to destroy a few walls from a grid that I created.Also, I am trying to solve the Maze through Dijkstra Algorithm. For this, I have to check whether the cell(unit of Grid) has wall or not. Unfortunately, the statement when checked for “null” does not compute to true.
In Maze Generator Script
Here the wall are instantiated using :
tempWall = Instantiate(wall, newPos, Quaternion.identity) as GameObject;
and are later destroyed using :
Destroy(cells[_currentCellNumber].up);
Cells Script(not derived from MonoBehaviour)
[System.Serializable] public class Cells{ public bool visited = false; public GameObject up; // 1 public GameObject down;// 2 public GameObject left;// 3 public GameObject right;// 4 }
##Checking in Dijkstra Solve Maze
if (cells[currentCellNumber].left.gameObject == null
Unfortunately, the block of statement for ‘If’ is never executed.
But if the code is changed to:
if (cells[currentCellNumber].left.gameObject != null)
The statement does get executed,but for all the wall, also which does not exist.
Pleaes help me, thanks in advance!