Question by
Unconscious · May 15, 2016 at 01:25 PM ·
arrayrandom
How to pick two random gameobjects in an array at the same time?
How to pick two random gameobjects in an array at the same time?
this code only pick one
int index = Random.Range (0, results.Length);
current = results [index];
Comment
Best Answer
Answer by JackMini36 · May 15, 2016 at 04:25 PM
Do it twice, and just check for duplicates
int index1 = Random.Range (0, results.Length);
int index2;
do
{
index2 = Random.Range (0, results.Length);
}
while (index1==index2)
current1 = results [index1];
current2 = results [index2];
Your answer
![](https://koobas.hobune.stream/wayback/20220612080825im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
randomly activate one of many gameobjects ?? 4 Answers
Printing a random value from an array. 1 Answer
how to not repeat random array 1 Answer
Random Generator Instantiate Tiles C# = PLEASE HELP = 0 Answers
Random array with prefabs? 2 Answers