- Home /
Question by
Jaedong · Oct 25, 2018 at 05:40 PM ·
arrayrandom.range
Random array size
I have an array of blocks. I want it to be with a random size/length when the scene starts.
public GameObject[] blocks;
However if I try random range with an array I get all kinds of errors...
Any suggestions?
Comment
Best Answer
Answer by KittenSnipes · Oct 25, 2018 at 06:10 PM
This should work:
GameObject[] blocks;
void GenerateBlocks() {
int rand = Random.Range(1, 26);
blocks = new GameObject[rand];
}
Your answer
Follow this Question
Related Questions
pick a random int with the value of 1 from an array 2 Answers
how to have an array in instantiate function 2 Answers
Create an array that chooses between four random numbers (C#) 3 Answers
How to randomly pick a gameobject except for one gameobject in an array ? 1 Answer
Assign role randomly from array 2 Answers