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 /
  • Help Room /
avatar image
0
Question by Garndaddy · Nov 16, 2013 at 09:31 PM · c#enumattribute

Can I set one enum value equal to another enum value?

I'm working on a football simulation game and I need to assign the players different attributes. For Example: Justin Miller, 85 speed, 85 strength, etc. Is there any way that i can make an enum for the names and one for the attributes, and set them equal to each other?

Any help is greatly appreciated!

p.s. The scripts are in c#.

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 ArkaneX · Nov 16, 2013 at 09:34 PM 1
Share

You can have attributes enum, but I guess a Player class with Strength, Speed, etc. integer properties would be more suitable solution. Hard to say without full knowledge of your idea...

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by MrVerdoux · Nov 16, 2013 at 10:09 PM

I´m not very sure what you mean but I´ll try to answer your question.

You can set an enum value equal to another enum value, casting it twice (or at least that´s how I would do it. For example:

 enum Enum1{
     hi,
     bye
 }
 
 enum Enum2{
     foot,
     hand
 }
 
 Enum1 enum1;
 Enum2 enum2;
 
 void CastEnum2ToEnum1(){
     enum1 = (Enum2) ((int) enum2);
 }

However that seems a terrible idea and that is not how enums should be used. Diferent enums should not assign each other because they handle information that is independent and uncomparable conceptually.

Comment
Add comment · Show 1 · 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 Garndaddy · Nov 16, 2013 at 10:11 PM 0
Share

Thanks for the help. I think I found another way to do what I need.

avatar image
0

Answer by darshie1976 · May 05, 2016 at 05:04 AM

Yes you can.

Enums are nothing but a struct with constants; you assign arbitrary values as you wish, with the understanding that

  • you can only use int values

  • you are forced by logic to assume that 2 enum entry, with the same value, are in fact the same entry

public enum myEnum { wine = 10, water = 2, wateredwine = 3, wateredliquor = 3, liquor = 10 }

In this statement, you are assuming that wine and liquor are the same, because they have the same value; same for watered wine and watered liquor.

If this is illogic, depends from how do you use the enum in which context. If you use it to set values for a multiplier for example, in a pinball game; it makes totally sense that you have different entry with the same enum value:

 public enum myEnum
 {
     bridge1 = 10,
     bumper1 = 2,
     ramp1 = 3,
     ramp2 = 3,
     bridge2= 10
 }

In this case you know that bridge1 and bridge2 are different entry, but you use them for their multiplier; same for ramp1 and ramp2.

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

20 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

C# naming related enum, private member and public accessor. 2 Answers

Restrict amount of multiple choices per Enum 0 Answers

Accesing enum type from another script 1 Answer

Using enum as a string with an if statement 1 Answer

how to save time and take the next variable in enum? 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