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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Multiple Selection Enum?

Discussion in 'Getting Started' started by joemost29, Jul 31, 2015.

  1. joemost29

    joemost29

    Joined:
    Jul 2, 2014
    Posts:
    11
    Hey Guess,

    For my game I have a class with an Enum in it, Depending on what enum is selected it gives the weapon different attributes. What I am trying to figure out how to do however is allow the weapon to have multiple attributes...

    say one weapon has a fire and a water attribute, normally I would set it up like

    enum WeaponAtri {
    Water,
    Fire,
    Earth
    }

    and the weapon would have one of those three, what If I wanted it to have two?
     
  2. joemost29

    joemost29

    Joined:
    Jul 2, 2014
    Posts:
    11
    would it be is simple as ItemClass.weaponAtri.Water,Fire
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Ditch the enum and use a set of bools instead. So you'd have water = true, fire = false, etc.

    --Eric
     
  4. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    Your weapon class could have an array of WeaponAtri. Although, since they are simple toggles, using bools as Eric said may be simpler in the long run anyway.
     
  5. joemost29

    joemost29

    Joined:
    Jul 2, 2014
    Posts:
    11
    hmm, so if you have a lot of abilitys i guess that could get really long creating an item each time, but i guess it would be better
     
  6. joemost29

    joemost29

    Joined:
    Jul 2, 2014
    Posts:
    11
    hmm maybe ill just bite the bullet and have a ton of bools
     
  7. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    There's no one right way. If you like enums and would rather compare against that, then by all means, do so. I find that when it comes to conforming to "best practices" vs doing something that makes sense to you, you should almost always go with the second option. Unless you're sharing code with a team and other people have to understand what you're doing, the most important thing is making progress and eventually finishing your game, right?