- Home /
Get a list of options for variable in the script inspector?
I feel like I've seen this before, but I can't figure out how to do it. Is there a way to have a variable have a list of options you can choose in the inspector?
Answer by Molix · Feb 24, 2011 at 03:16 AM
Depending on the kind of variable you want, you could use an enumeration (enum). Enums are automatically serialized and displayed as a little dropdown list in the inspector. e.g.
// declare the enum somewhere visible public enum MyEnumeratedType { FirstOption, SecondOption, ThirdOption }
// in your script, declare a public variable of your enum type public MyEnumeratedType option;
The underlying value is just an integer, starting from 0 (in this case, FirstOption would have a numeric value of 0).
Of course with a custom inspector, any type can have a list of options.
Combined with this http://answers.unity3d.com/questions/7950/how-to-declare-and-use-a-enum-variable-in-javascript got me my solution. Thanks for the help.
Thanks man! I didn't know the underlying value is just an integer! I was getting crazy, hardly realizing it is not a list of strings even if they look like unquoted strings.
I think you should bold that phrase for anyone having the same trouble.
Thanks again!
Is there a way to use integers as a variables?
e.g.
public enum $$anonymous$$yIntegersType
{
1,2,4,8,16,32,64,128
}
public $$anonymous$$yIntegersType intType;
Your answer
![](https://koobas.hobune.stream/wayback/20220613105950im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Javascript and C#, different behaviour in inspector ? 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Having Variables store a script in the inspector 2 Answers
Multiple classes inside each other 1 Answer
Is it possible to create a script dinamic like animation>size controling the Elements variables? 1 Answer