Random.Range not working

No idea why this changed but the random range isn’t working without adding UnityEngine.Random.Range.
I get the feeling it is because I’m using mirror templates.

This can depending on the using statements in the class. As well, it could be a change in the Unity engine, regarding which namespaces are included under the UnityEngine umbrella.

Did your code editor mention which namespace there was ambiguity with?

1 Like

Hey @Joshua_Gillespie . There are 2 “Random” methods - the .Net and the unity implementation. That’s why you need to specify which one you want to use. You can read more about them here Unity - Scripting API: Random

2 Likes

The random.range is working by changing the range from (0,1) to become (0,255), because of the color system is 0-255 by default also I checked by debug.log it shows that random.range is working well, but and the color change but actually not changing the main color!

Finally i found the solution, dont use the color alone use color32, because the color 32 accepts bytes instead of ints or floats put byte before the random.range, i just made the last variable fixed to be 255 in order to avoid transparent elements apply this code:

Color32 displayColor = new Color32 ((byte)Random.RandomRange(1, 255),(byte)Random.RandomRange(1, 255),(byte)Random.RandomRange(1, 255),255);

2 Likes

Privacy & Terms