Search Unity

How to make a select-between-two-options button in Inspector

Discussion in 'Getting Started' started by AlinS03, Jan 12, 2019.

  1. AlinS03

    AlinS03

    Joined:
    Dec 9, 2018
    Posts:
    5
    I've recently learnt how to make a slider for the inspector and few other useful things, but I can't find an attribute for a select button.
    I want to make a script that has a few options, for example:
    1)Make things red
    2)Make things green
    3)Make things blue
    And I also want to make a nice button to select one of these options in inspector, so the script knows what to do, a button like in the picture from the link below. (if you can't find the picture it means that I deleted it from Dropbox, so I probably don't need answers anymore)
    I know I can make a public int value, and select the range from 1 to 3 and eventually make a slider for it but it would be better with a select button, this way I can also see some text to each option in inspector.
    So can you guys tell me the easiest way to do that?
    Thanks.
    https://www.dropbox.com/s/u2gysv5oekz2y5z/Capture.PNG?dl=0
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Ah, I think you just want an enum. In your script, add something like this:

    Code (CSharp):
    1. public enum ThingColor {
    2.     Red,
    3.     Green,
    4.     Blue
    5. }
    6. public ThingColor thingColor;
    7.  
    and now you'll have a thingColor property, with a pop-up menu that lets you select any of those values in the inspector.
     
  3. AlinS03

    AlinS03

    Joined:
    Dec 9, 2018
    Posts:
    5
    JoeStrout yep, that's exactly what I was looking for, thanks a lot! It really came in handy!