If I understand correctly you may need this I stored each GameObject in Array of Gameobject YOu may not get an Exception here
GameObject[,] ArrayOfGameObjects = new GameObject[10, 10];
public void spawnGrid ()
{
for (int y = 0; y < 10; y++) {
for (int x = 0; x <10; x++) {
ArrayOfGameObjects[x,y] = Instantiate (YourPrefabGameObject, new Vector3 (x, y, 0),Quaternion.identity)as GameObject;
}
}
}
public CheckAdjOf (GameObject gameObj)
{
if (gameObj == null)
{
//Do your stuff if its null
//for example break, return
}
int x = (int)gameObj.transform.position.x;
int y = (int)gameObj.transform.position.y;
GameObject Left,Right,Up,Down;
if (x < mArray.GetUpperBound (0))
Right = ArrayOfGameObjects [x + 1, y] == 0);
if (x > 0)
Left = ArrayOfGameObjects [x - 1, y] == 0);
if (y < mArray.GetUpperBound (0))
Up = ArrayOfGameObjects [x, y + 1] == 0);
if (y > 0)
Down = ArrayOfGameObjects [x, y - 1] == 0);
// you can also find diagonal GameObjects
// do your stuff after you getting all adjunctive grid/block
}