I define the 2d array
public static bool[,] TileStates;
I set it in Start()
bool[,] TileStates = new bool[gridX,gridY];
But I test it in Update()
if ( TileStates[x,y] == true ){
I get object reference not set to an instance of an object!
Any clues?
Try initializing with a default value every position of the array
Thanks for coming back so quick!
Reading around it looks like I needed to fill the array before accessing it so I added
TileStates[x,y] = false; // set all tiles to LOCKED to start with.
in the loop, but still get the same pesky error ;(
Any other ideas?
Do you really want to declare the array static? That means it will be shared between all instances of your object. Also your line in Start() is declaring a new local variable, not assigning to the existing one.
Try this instead:
public bool[,] TileStates;
void Start()
{
TileStates = new bool[gridX,gridY];
// Other code
}
void Update()
{
// Other code
if ( TileStates[x,y] == true ){
// Other code
}
// Other code
}
That works and I understand where I went wrong.
Thanks for your patience!