Why doesn't random range work?
It only plays 0 each time this enumerator is triggered by a button press. I see no reason it shouldn't work...
int randomTailSound = Random.Range(0,1);
if (randomTailSound == 0)
{
Tail2.Play();
}
else if (randomTailSound == 1)
{
Tail1.Play();
}
Answer by meat5000 · Mar 14, 2018 at 11:58 PM
It does, you read the docs incorrectly
https://docs.unity3d.com/ScriptReference/Random.Range.html
the 'int' version is maximally EXCLUSIVE.
From the docs :
Returns a random integer number between min [inclusive] and max [exclusive] (Read Only).
Note that max is exclusive, so using Random.Range( 0, 10 ) will return values between 0 and 9. If max equals min, min will be returned.
No problem. Just to add this in, the float version is $$anonymous$$aximally INCLUSIVE, so actually reaches the $$anonymous$$ax value.
Your answer
Follow this Question
Related Questions
Need help with specifics in Random.Range 1 Answer
how to randomly choose a value from array 3 Answers
How to stop getting duplicate numbers while using random.range 1 Answer
Trying to implement xorshift with deplorable results (PRNG) 0 Answers
how to Spawn prefab infront off player and destroy it when hr passed it 0 Answers