Random.Range not working?

I just started learning C# in Unity, I have been following tutorials etc. for about 2 weeks. I’ve been using Visual Studio for writing the scripts. Well, when following tutorials previously, I had no problem using Random.Range. I did update my versions of Unity and Visual Studio to be up-to-date as of today, so maybe that is where my problem lies? As of today, if I type Random.Range it does not recognize it, and it only gives me the option of the function just called “Random” or it suggests something called RandomNumberGenerator. I’m not sure if I’ve messed something up somewhere but it does this on a new C# script, using the defaults (System; System.Collections; System.Collections.Generic; UnityEngine) and inheriting from MonoBehavior. Can anyone explain this? Thank you.

Edited:

Actually, nothing is working now. I am getting compiler errors from just doing a Debug.Log Hello World. I will add a screenshot.

The issue is your code, not unity. A c# method declaration must be followed by parentheses.

So it should be void OnDisable() { }

The compiler is correct.

As for the Random issue, stop using System; Both system and UnityEngine contain Random classes, the ide thinks you want to use the random class in the System namespace and not UnityEngine.

If you really need to use the system namespace, then add using Random = UnityEngine.Random; to your script.

2 Likes

Ah, duh. I think I fried my brain trying to figure out the random stuff. That was a silly error. Thank you for your response. I will try getting rid of System!

Edit: I still can’t get Random.Range. Every time I try, Visual Studio automatically populates with System. I feel like this change must be from my updating VS? Any additional tips are appreciated.

Put this at the top of your file:

using UnityEngine;
using Random = UnityEngine.Random;
1 Like