Search Unity

Unity's Random class same name as .net's Random class...

Discussion in 'Editor & General Support' started by jeremyace, Apr 16, 2006.

  1. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    I just found this out today, Unity's Random class has the same name as .net's System.Random class. So if you are using System and try to use Unity's random functions, you get an error.

    Was it intended to have the same name? Because that is weird and causes problems.

    Thanks,
    -Jeremy
     
  2. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    The two classes are in separate namespaces. You'll just have to fully qualify the name of the classes:
    Code (csharp):
    1.  
    2. UnityEngine.Random.value;
    3. new System.Random();
    4.  
    In C# you can also import both by renaming them with the using statement:
    Code (csharp):
    1.  
    2. using URnd=UnityEngine.Random;
    3. using SRnd=System.Random;
    4.  
    5. // ...
    6.  
    7. URnd.value;
    8. new SRnd();
    9.  
    10.  
     
  3. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Cool, thanks freyr.

    -Jeremy