- Home /
Picking one of two numbers.
I'm still kind of a noob at this so forgive me if the answer seems a bit obvious, but if I have two or more numbers in a series (Ex: 180,90,270) how would I randomly pick one of those exact numbers without getting complicated?
you'd really think this forum is now easily big enough (50,000 questions) to break it in to
a) advanced Unity questions
b) beginner Unity questions
c) general program$$anonymous$$g questions (I suggest calling this section "Program$$anonymous$$' Puzzles!" or something)
Again at 50,000 questions it's really a shame they don't put a little time in to this. it would be excellent to have a separate "advanced" questions section, facility, division, or whatever.
Answer by Eric5h5 · Jun 12, 2012 at 01:02 AM
That exact series?
Random.Range(1, 4) * 90
Some arbitrary series:
var numbers = [1, 5, 10, 20];
var pick = numbers[Random.Range(0, numbers.Length)];
Just keep in $$anonymous$$d that Random.Range for int return inside an interval [,[ (inclusif, exclusif). That's why Eric is using (1, 4) and not (1, 3).
What if i don't want a range but just one number or the other?
Thanks!
Random.Range(0,2)
Will return the number 0 or 1.
Your answer
Follow this Question
Related Questions
How can I Instantiate an Object from a Randomly Selected Index in an Array of Game Objects? 1 Answer
Store multiple random integers in an array? 4 Answers
Randomly Choosing two objects from an array and switching their positions 3 Answers
C# Array with random.range help? 2 Answers
how to check for GameObject is null in array with random 1 Answer