get a random number in unity code example
Example 1: random number generator unity
int num = Random.Range(min, max);
Example 2: unity random int
//If you use Int in the Random.Range() then it will
//return an Int
public int RanTimerHigh = 10;
public int RanTimerLow = 1;
void Start()
{
int RandomInt = Random.Range(RanTimerLow, RanTimerHigh);
}
Example 3: unity random
var RandomValue = UnityEngine.Random.Range(min,max);
Example 4: 10 random numbers unity
void Start(){ //having an int Array of 10 members int [] numbers = new int[10]; //using a string variable to keep record of the used numbers string usedNumbers ="-"; //cycle to get 10 random numbers for (int i = 0 ; i<10; i++) { //get a random number between 0 - 120, 0 and 120 included on the random numbers int randomNumber = Random.Range(0,121); //Checking if the random number you get is unique, if you already have it in the string means that this random number is repeated, the "-X-" is to make the difference between the numbers, like -1- from -11-, if you dont have the "-X-" the 1 is in 21 and would be a "repeated" number while(usedNumbers.Contains("-"+randomNumber.ToString()+"-")) { //if a number is repeated, then get a new random number randomNumber = Random.Range(0,121); } usedNumbers+= randomNumber.ToString()+"-"; numbers[i] = randomNumber; }}