- Home /
Question by
sona.viswam · Feb 21, 2013 at 11:05 AM ·
objectrandomrangeunion
Random Range with limits
I declared
Vector3 position = new Vector3(Random.Range(x, y), 0, 0);
i need value from 5-10 and 20-25 for x and y.
Usually i used to give
Random.Range(-0F,-2F);
But here its not possible.
Is any union function in unity?
or any other method ???
Waiting for gentle ideas and proper reply.
Thanks in Advance.
Comment
Best Answer
Answer by GuyTidhar · Feb 21, 2013 at 11:48 AM
Why not:
Vector3 position = new Vector3(Random.Range(Random.Range(5,10), Random.Range(20,25)), 0, 0);
Answer by fafase · Feb 21, 2013 at 11:57 AM
I have read before there is no such thing in the Unity implementation. You would have to do it yourself.
int GetRange(){
int a = Random.Range(5,10);
int b = Random.Range(20,25);
if(Random.Range(0,2)==0)
return a;
else
return b;
}
Your answer
Follow this Question
Related Questions
Avoid getting same object as previous one with Random.Range? 2 Answers
A node in a childnode? 1 Answer
How can i randomly create an array of objects without colliding one another? 1 Answer
Store multiple random integers in an array? 4 Answers
[Beginner] Using Random.Range in initial game object position 1 Answer