FYI: In case Visual Studio gives Warning for Random function

I just wanted to point out that the Random.Range function that the teacher is using is part of the namespace UnityEngine. I noticed that my Visual Studio 2022 app warning me about an ambiguous reference between UnityEngine’s Random function and the namespace System’s Random function. The solution to clear the warning, according to Visual Studio 2022, which worked, is having an alias statement like the following:

using Random = UnityEngine.Random;

of course this statement is not entirely necessary for the code to compile properly and can be left out. Apparently I did not see Visual Studio Code flag this in the video, so maybe not all IDE programs complain about this ambiguity. For more information you can go to this webpage to learn about Unity’s Random function: Unity - Scripting API: Random

It all depends on the usings clauses in general…
For example, I like to strip

using System;

from my usings clauses altogether. In fact, the first thing I do with a new class is remove unneeded usings, a feature found in all three of the major code editors (I use JetBrains Rider).

This does mean that I have to specify certain things, mainly System.Actions and System.EventHandlers.

I do this in Rider, because one of the few annoying things in it’s helpful intellisense is that it automatically adds

using Random = System.Random;

whenever I have the using System; namespace and type Random… and of course, since Rider generously did that, Random.Range() no longer has any definition at all!

Privacy & Terms