Why does one need to use "UnityEngine"?

I ask this question because I want to better understand how scripting works in Unity. I recently started practicing the use of Random.Range. When I start to use a new concept in Unity, I make a simple scene for testing. Then, when I feel I have a good understanding of the concept, I incorporate the new concept into my larger game. When using Random.Range, Unity kept posting the error “‘Range’ is not a member of ‘Random’.” This drove me crazy for over 2 hours as I tried different versions of scripts posted all over the internet. I finally found that using “UnityEngine.Random.Range(1,10);” fixed the problem, but I do not fully understand why. Can anyone please shed some light onto when “UnityEngine” is required and not required? I have a feeling I will be running into this use again and I want to save myself the grief of going through it again. Thank you in advance for your time and effort.

Unity Ver 4.2.0F4

BTW - Adding the tag “water3” was the only way I could figure out how to post my question.

Unity classes and functions are under the “UnityEngine” namespace.

So whenever you want to use the classes/functions in the 1, you should put “using UnityEngine;” at the head of your script, or everytime you call like “UnityEngine.Random.Range(1,10);”

There are two “Randoms”.

One is system’s random and one is unity’s random.

The system’s random doesn’t have the range option.

So when compiling, your compiler thought you meant the system random and gave you the error.

BTW - When asking a question, so must add a tag (any tag).
Please try adding a more appropriate tag next time.

I guess your script only imports the System namespace (via using System;) and this namespace also contains a class called Random. But this class doesn’t contain a method named Range. That is the reason why the messages says that Range is not a member of Random. It just uses the System.Random class.

To solve this you can either give the full qualified path as you already did (UnityEngine.Random.Range) or import the UnityEngine namespace before the System namespace

`
using UnityEngine;

using System;
`

Now Random.Range is the same as UnityEngine.Random.Range. If you now want to use the Random class from the c# library you have to write System.Random.MethodName.