- Home /
Question by
nizameddinkale · Aug 03, 2020 at 01:32 PM ·
arrayprefabsstringfindgameobjectswithtagindexoutofrangeexception
How to learn amount of objects in selected prefabs folder?
Hello i want to know how many GameObjects in Source/Prefabs/Tetris but tetrisBlocks value is 0 or null? i guess cause im getting ~IndexOutOfRangeException: Index was outside the bounds of the array. tetrisGameController.GetRandomTetrisBlock ()
i searched on google but couldn't come up with solution.
.Question: How many objects in Source/Prefabs/Tetris how can i learn?
string GetRandomTetrisBlock()
{
GameObject[] tetrisBlocks = GameObject.FindGameObjectsWithTag("TetrisBlock");
int randomTetrisBlockGenerator = Random.Range(1, (tetrisBlocks.Length));
string[] tetrisBlockArray = new string[tetrisBlocks.Length];
for (int i = 0; i < tetrisBlocks.Length; i++)
{
tetrisBlockArray[i] = "Prefab/Tetrsi/Tetris_" +i;
}
return tetrisBlockArray[randomTetrisBlockGenerator - 1];
}
Thanks~~~~
Comment