Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by Gilead7 · Mar 29, 2012 at 05:04 PM · c#random.range

random issue

Random' is an ambiguous reference between UnityEngine.Random' and `System.Random'

I am attempting to create a variable with a value between 1 and 20. I set it to private. int _variable=Random.Range(1,20); but when I put it into a gui label, it spits out the above error. I have: using UnityEngine; using System.Collections; using System; At the top. What am I missing????????? Thanks!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FLASHDENMARK · Mar 29, 2012 at 05:08 PM 0
Share

It may be a copy/paste issue, but why is there a . after private?

3 Replies

· Add your reply
  • Sort: 
avatar image
16
Best Answer

Answer by sebas77 · Mar 29, 2012 at 05:12 PM

well just explicity choose which one you want to use and write

int _variable=System.Random.Range(1,20); OR

int _variable=UnityEngine.Random.Range(1,20);

honestly I do not know which one you should use, but I guess is the second one (just checked, it is the second one ;) )

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gilead7 · Mar 29, 2012 at 05:32 PM 0
Share

Thanks! I wonder, why the change? It's not mentioned anywhere else. These kinds of things make it very hard to learn this stuff.

avatar image Eric5h5 · Mar 29, 2012 at 05:38 PM 2
Share

There is no change, it's because you're importing both the UnityEngine and System namespaces, both of which have Random. So you have to tell it which one you're referring to. If you're not using anything from System, don't import the namespace; it's not a standard thing to import in Unity.

avatar image Gilead7 · Mar 29, 2012 at 09:39 PM 0
Share

I was using System so I could utilize the enum list in another script.

avatar image Eric5h5 · Mar 29, 2012 at 09:44 PM 0
Share

Enums don't need System.

avatar image Bunny83 · Mar 30, 2012 at 02:22 AM 0
Share

No, enums don't need the system namespace, but the Enum class. However if you use the Enum class just at a few spots it's better to use the full classname (System.Enum) ins$$anonymous$$d of importing the whole System namespace.

When you import multiple namespaces there's always a chance that you end up with ambiguous class names. Only import those namespaces you need the most.

Show more comments
avatar image
29

Answer by Martian-Games · Oct 19, 2015 at 03:05 AM

just add this line:

 using Random=UnityEngine.Random;

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bachar-hamza · Aug 28, 2017 at 10:08 AM 0
Share

Thanks, worked for me.

avatar image Rexor4321 · Oct 02, 2017 at 07:51 AM 0
Share

$$anonymous$$Y GOD, thank you!!!

avatar image
0

Answer by EliezerYT · Apr 03, 2020 at 12:05 AM

esto es viejo jaja pero mi conclusion que encontre esque System Y UnityEngine tiene diferentes funcion cada una del Random... por lo que si usas la classe inicial de UnityEngine y System va a chocar y pide que cual exactamente quieres usar por lo que antes se deberia poner el UnityEngine.Random.Range(x,y) y asi

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Randomly Select String from Array 0 Answers

Random.Range, GameObjects and Length 1 Answer

Randomizer code not working. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges