Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Enums help!

Discussion in 'Scripting' started by ThomasSoto, Apr 18, 2018.

  1. ThomasSoto

    ThomasSoto

    Joined:
    Aug 7, 2013
    Posts:
    26
    I'm trying to use enums to give the Player a set of Abilities that each CharacterClass has. The Issue I'm having is that on the Editor I can't see the "Abilities" Enum. I have the following code. Please take a look and give me a little push if you can!

    Code (CSharp):
    1.  
    2.     public enum CharacterClass {
    3.         Offense,
    4.         Defense
    5.     };
    6.  
    7.     [System.Serializable]
    8.     public class Abilities {
    9.     }
    10.        
    11.     public class OffenseAbilities : Abilities {
    12.  
    13.         public enum Power {
    14.             DamageBoost,
    15.             StunGrenade,
    16.         };
    17.         public Power power;
    18.  
    19.         public enum Agility {
    20.             MeleeDash,
    21.             DoubleJump,
    22.         };
    23.         public Agility agility;
    24.  
    25.         public enum Wisdom {
    26.             CriticalHit
    27.         };
    28.         public Wisdom wisdom;
    29.  
    30.         public enum Sense {
    31.             MeleeDamageBoost,
    32.             BlasterDamageBoost,
    33.         };
    34.         public Sense sense;
    35.  
    36.     }
    37.     OffenseAbilities offenseAbilities = new OffenseAbilities ();
    38.  
    39.     public class DefenseAbilities : Abilities {
    40.  
    41.     }
    42.     DefenseAbilities defenseAbilities = new DefenseAbilities ();  
    43.  
    44.     public CharacterClass characterClass;
    45.     public Abilities abilities;
    46.  
    47.  
    48.     void Update() {
    49.  
    50.         switch (characterClass) {
    51.  
    52.         case CharacterClass.Offense:
    53.             abilities = offenseAbilities;
    54.             break;
    55.            
    56.         case CharacterClass.Defense:
    57.             abilities = defenseAbilities;
    58.             break;
    59.  
    60.         }
    61. }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,599
    In your code, Abilities is a class, not an enum... what are you expecting to see in the editor and what are you not seeing?
     
  3. ThomasSoto

    ThomasSoto

    Joined:
    Aug 7, 2013
    Posts:
    26
    I'm expecting to see the enums listed in the selected CharacterClass. So when I select the Offense class I see all the Enums listed under OffenseAbilities. Not sure if I'm making myself clear.
     
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,383
    That doesn't happen magically, you have to make a custom editor to display things in the inspector based on what that Enum is set to.

    Enums are serialized and show in the inspector by default. Just make a variable
    public CharacterClass ThisGuysClass;
    .
     
    Joe-Censored and Kurt-Dekker like this.
  5. ThomasSoto

    ThomasSoto

    Joined:
    Aug 7, 2013
    Posts:
    26
    Yeah that's what I was afraid of. I'll have to dig in to custom editors. I currently have a public CharacterClass on line 44 and a public Abilities on line 45. The Character Class is updated and shows on the editor without any issues. It's the Abilities that doesn't show any variables / enums
     
  6. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,383
    Correct, you have given it zero connection between the two, so there's nothing for it to do.
     
  7. ThomasSoto

    ThomasSoto

    Joined:
    Aug 7, 2013
    Posts:
    26
    Yes there is a connection with the switch on Update that changes the Ability depending on the value of CharacterClass