Random.range()

I have a little question.

In the course we have to use the Random.range() ofcourse.
The thing is that this piece of code does not work for me. instead I need to use
UnityEngine.Random.Range()
Is that okay? I seem to get the same results out of it.
if I use random.range() an error shows up.
lecture 43 randomrange screen

So instead I use UnityEngine.Random.Range().
Just want to make sure that is okay.

unity version: 2020.1.6f1
Visual studio version: 2019 16.7.7

Hi Kederin,

Yes, UnityEngine.Random.Range is perfectly fine. The ambiguity stems from the namespace Visual Studio added to your script. You could try to remove the System namespace.

Does MonoBehaviour have the same colour as your classname? If not, there might be a problem with Visual Studio. Please watch lecture “Fixing Visual Studio Problems” (currently #4).

Did this help?


See also:

Then I will leave it as it is. MonoBehaviour has the same color as my classname, so that should be fine. I’ll just make a note for myself to put “UnityEngine.” before the line of code if I use the RandomRange() code.

Thanks.
Joey (kederin)

Alternatively, you could use a using alias directive.

using Random = UnityEngine.Random;

That should solve the ambiguity, and you should be able to use Random.Range without UnityEngine in front of it.

I will definitely try that out, that might get rid of my own confusion.

Thanks

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms