going through each item of a multi-dimensional array

Hi,

i have a basic level that consists of a two-dimensional array of GameObjects. How can I delete all of them?

i did

var board:GameObject[,];
board = new GameObject[3,3];

and then i want a lil loop that wipes everything out.

for (var i = 0; i < board.length; i++)
    {
    	for (var j = 0; j < board*.length; j++)*
  • {*
  •  Destroy(board[i,j]);*
    
  • }*
    }
    doesn’t work, though :confused: (“‘length’ is not a member of ‘UnityEngine.GameObject’.”)

You have to use GetLength(dimension) instead of length. the dimension is 0 for first dimemension and 1 for the second (and so on, if you have a 3-dimension array).

for(var x = 0; x < myArray.GetLength(0); x ++)
	{
		for(var y = 0; y < myArray.GetLength(1); y ++)
			{
                         Destroy(myArray[x,y];
                        }
        }