guys i need your help, it seems some alien lifeform has pulled the simplest coding skills from my brain:
when i do the following as a declaration:
public int sizeA = 10;
public int sizeB = 15;
private GameObject[][] objects;
the compiler wont let me do this in my start() ;
objects = new GameObject[sizeA][sizeB];
i get an error: Assets/Scripts/CubePlane.cs(25,40): error CS0178: Invalid rank specifier: expected ,' or
]’
i guess i miss the forest, standing in front of all the trees here, what do i do wrong ?
thx in advance guys
chris
That’s because you’re using [jagged arrays][1], which are supposed to be initialized like so:
objects = new GameObject[sizeA];
for (int i = 0; i < sizseA; ++i)
objects *= new GameObject[sizeB];*
You’re probably better off using [multi-dimensional arrays][2]:
private GameObject[,] objects;
objects = new GameObject[sizseA,sizeB];
[1]: Jagged Arrays - C# Programming Guide | Microsoft Learn
[2]: Multidimensional Arrays - C# Programming Guide | Microsoft Learn
ok i think i found the answer for myself: i used a so called “jagged array” ; which is GameObject and you cant, for whatever reason, initialize the way i did
… however … when using a true multidimensional array, corresponding to c# syntax you can do the following:
private GameObject[,] objects;
objects = new GameObjects[sizeA,SizeB];
that works fine…
Here is the C# documentation for arrays, could be useful for you. https://msdn.microsoft.com/en-us/library/aa287601(v=vs.71).aspx