- Home /
C# - 2d Array Length
I have a 2d array of gameobjects set up like this:
protected GameObject[,] pedestrianPrefabs;
pedestrianPrefabs = new GameObject[,] {{shellControllerScript.AdultMale_Prefab, shellControllerScript.AdultMale_Prefab2, shellControllerScript.AdultMale_Prefab3}, {shellControllerScript.Granny_Prefab}};
Im then trying to pull out a random Gameobject from a specific dimension like this:
GameObject randomSkin = pedestrianPrefabs[0, UnityEngine.Random.Range(0,pedestrianPrefabs.GetLength(0))];
I can seem to get the length of one of the inner arrays. Length, GetLength, GetUpperBound dont seem to work.
Halp pls
Comment
yes i did : Wrong number of indexes '1' inside [], expected '2'
Answer by prakyathd801 · Nov 12, 2020 at 05:16 AM
myArray.GetLength(0) -> Gets first dimension size
myArray.GetLength(1) -> Gets second dimension size
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Put user list in 2d array 1 Answer
2D Hex/ Square Tile Resource Controller Help 0 Answers
Weird - IndexOutOfRangeException: Array index is out of range. 1 Answer