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
0
Question by Gilead7 · Mar 13, 2012 at 12:40 AM · c#enumtostring

Enum to int issue

I am attempting to put my character generator together. I'm pulling the enum values from the attributes script and want to display them as a string. The error that comes up is- cannot convert type to int. The more I try to fix it, the more it come up with problems.

 for(int ctr = 0; ctr < Enum.GetValues(typeof(Attribute)).Length; ctr++){
 
     GUI.Label(new Rect(10, 40+(ctr * 25), 100, 25), ((Attribute)ctr).ToString());
 
 }
 

What am I doing wrong? Thanks!

Comment
Add comment
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

1 Reply

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

Answer by syclamoth · Mar 13, 2012 at 12:45 AM

You need to cast the 'Enum.GetValues' back to an int:

 for(int ctr=0; ctr < (int)Enum.GetValues(typeof(Attribute)).Length; ctr++){
     GUI.Label(new Rect(10, 40 + (ctr * 25), 100, 25), ((Attribute)ctr).ToString());
 }
Comment
Add comment · Show 3 · 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 13, 2012 at 07:33 PM 0
Share

Thanks! I must have missed something along the way because I got another error of the same type. Assets/Scenes/CharacterGenerator.cs(21,67): error CS0030: Cannot convert type int' to System.Attribute'

Also getting(maybe old) Assets/Scenes/CharacterGenerator.cs(21,9): error CS1502: The best overloaded method match for UnityEngine.GUI.Label(UnityEngine.Rect, string)' has some invalid arguments and Assets/Scenes/CharacterGenerator.cs(21,9): error CS1503: Argument #2' cannot convert object' expression to type string' Having a very hard time with this...

avatar image syclamoth · Mar 14, 2012 at 12:42 AM 0
Share

It's because you went and named your enum 'Attribute'. Call it something different- it's getting confused between your enum, and the System.Attribute class.

avatar image Gilead7 · Mar 14, 2012 at 03:51 PM 0
Share

Thanks! I'll do that.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Cast the result of an enum as a string 3 Answers

Default Editor : Enum as flags ? 8 Answers

How to assign Enums to button? 0 Answers


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