In this lecture, Rick using the UnityEngine.Random.Range to generate random sounds,
but in the number wizard ui lecture,there is a "guess = Random.Range(min, max +1).
I want to know the Difference between Random.Range & UnityEngine.Random.Range .
so confused right now
Depending on which namespaces you include, there are generally two ways to generate random numbers. You can access them via System
and UnityEngine
.
Since you tend to include using UnityEngine
at the top of the script by default, you can omit the namespace when using it, so UnityEngine.Random.Range
and Random.Range
are exactly the same. if that’s the case then Rick may have just written it out the long way for clarity.
If using UnityEngine
is missing from the top of your script then you’d have to write it out the long way, or the compiler won’t know what you’re trying to do.
If you’ve also included using System
at the top of the script then you’d also need to specify which one you want to use or the compiler might complain (or it may do weird things at runtime), as it will be confused as to whether you’re trying to use System.Random
or UnityEngine.Random
.
I hope that helps.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.