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 Olgo · Sep 17, 2013 at 05:02 PM · enumvaluereturn

How is this always the same outcome?? Caution: contains sex! ;)

Hey Guys, I'm running in to a weird problem that I'm sure is a simple solution but for some reason when I always get the "NoGender = 0" value returned in my enum even tho all the other variables in my Sex class return appropriately. Have a look at the constructor then see the output below:

 public enum Gender {
     NoGender = 0,
     Male = 1,
     Female = 2,
     COUNT = 3
 }    
 
 public class Sex {
     public Gender gender;
     public string name;
     public string possesiveName;
     public string thirdPersonName;
     public string youngName;
     public string grownName;
     public Vector3 sexScale;
     public int[] hairIndexes;
     
     public Sex(Gender gender) {
         if(gender == SexData.Gender.Male){
             gender                 =     SexData.Gender.Male;
             name                =    "Male";
             possesiveName        =    "his";
             thirdPersonName        =    "he";
             youngName            =    "boy";
             grownName            =    "man";
         }
         else if(gender == SexData.Gender.Female){
             gender                =    SexData.Gender.Female;
             name                =    "Female";
             possesiveName        =    "her";
             thirdPersonName        =    "she";
             youngName            =    "girl";
             grownName            =    "woman";
             sexScale            =    new Vector3(.8f, .9f, .8f);
         }
         else{
             gender = SexData.Gender.NoGender;
             name = "No Gender";
         }    
     }
 }

Meanwhile; In another script....

 int temp = UnityEngine.Random.Range( (int)SexData.Gender.Male, (int)SexData.Gender.COUNT );
 characterSex = new SexData.Sex((SexData.Gender)temp);
 Debug.Log(characterSex.gender + " = " + (int)characterSex.gender + " aka " + characterSex.name);

Will always output in the console: "NoGender = 0 aka Female" or "NoGender = 0 aka Male" In short, characterSex.gender always returns the same while characterSex.name (set in the constructor) returns appropriately!! I'm lost, thanks for the help!

Comment
Add comment · Show 2
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 Jamora · Sep 17, 2013 at 05:25 PM 0
Share

What's the difference between SexData.Gender and Gender? Assu$$anonymous$$g they're they same, your random range is in the exclusive range (1,3(, so it is indeed quite suprising you get "NoGender = 0"...

avatar image Olgo · Sep 17, 2013 at 05:32 PM 0
Share

Yeah, they're the same. SexData is just the class that my Sex class is located in

1 Reply

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

Answer by Jamora · Sep 17, 2013 at 05:34 PM

You're assigning to the gender variable passed as a parameter.

You need

 if(gender == SexData.Gender.Male){
     this.gender = SexData.Gender.Male;
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 Olgo · Sep 17, 2013 at 05:36 PM 0
Share

gah!! i can't believe it! I think I'll change the passed variable name to "g" or something less dumb.

thanks for the help!

avatar image Bunny83 · Sep 17, 2013 at 06:53 PM 0
Share

That's why all my function parameters start with a small "a" (for argument) like (Gender aGender) ;)

avatar image Olgo · Sep 17, 2013 at 09:32 PM 0
Share

i did not know that, thanks :)

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

17 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

Related Questions

Get enum value out of function c# 2 Answers

transform.position related compile error fixed don't understand why ? 1 Answer

Use enum value as a index variable of a list 1 Answer

How do I use an enum value as a variable? 3 Answers

using enum value in cs? 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