Use Random.value instead of Random.Range(0f, 1f)

Hey, quick tip here! There is a build in function in the UnityEngine namespace called Random.value . It returns a random float between 0 and 1 (inclusive) and is a shorter way of writing Random.Range(0f, 1f)

6 Likes

Even better, there is a Random.ColorHSV that returns a random color.

7 Likes

What I particularly like about UnityEngine.Random.ColorHSV is that it gives you some control over the hue, saturation and value ranges, so that you can ensure your team colours are, say, nice and bright by limiting S and V to higher values:

    player.SetTeamColor(UnityEngine.Random.ColorHSV(
            0.0f, 1.0f,      // H range
            0.8f, 1.0f,      // S range
            0.7f, 1.0f));    // V range
4 Likes

Cool tip! Fun colors are way more fun!

1 Like

Privacy & Terms