Hello. How can I use Random.Range(#,#) in combination with an if statement? So I can do something like
(Random.Range(1, 10); if =1 {something} if =2 {something else} if =2 {something else} ...
Thanks
Hello. How can I use Random.Range(#,#) in combination with an if statement? So I can do something like
(Random.Range(1, 10); if =1 {something} if =2 {something else} if =2 {something else} ...
Thanks
`Random.Range(a,b)` returns a number between the two endpoint numbers `a` (inclusive) and `b`, (exclusive). This means, it will return anything between `a, a+1, a+2 ... b-2, b-1`
To use it, you will want to assign a variable `var rand:int=Random.Range(1,10);`, and then, compare it to the various possibilities in your if then. `if(rand==1)doSomething(); else if (rand==2)doAnotherThing();` etc.
You may also wish to use `if(rand>1)` and comparison operators for entire ranges of numbers.
You can also use a switch statement.
var randomNumber:int = Random.Range(0, 2);
switch(randomNumber){
case 0: //Do this, do that break; case 1: //Do this, do that break; case 2: //Do this, do that break; }