- Home /
Display a variable only if the right Enum is selected?
Hey, would it be possible to make a it so that a specific variable will only appear in the inspector if the right Enum is selected. To visualize it here is what I thought it would look like:
public class Item_Database : MonoBehaviour
{
public Items[] items;
public enum ItemType {Edible, Drinkable, Weapon}
[System.Serializable]
public class Items {
public string name;
public ItemType itemType;
if(ItemType == Edible) {
public string howMuchRestore;
}
}
}
Thanks in advance!
Answer by grahnzz · Aug 19, 2014 at 04:39 PM
Yes this is possible with a custom inspector http://unity3d.com/learn/tutorials/modules/intermediate/editor/building-custom-inspector
[CustomEditor( typeof(YourBehaviour) )]
public class InspectorYourBehaviour : Editor
{
public override void OnInspectorGUI()
{
YourBehaviour yourBehaviour = (YourBehaviour)target;
if(yourBehaviour.enum == value1)
{
//do something for value1
}
}
}
It gives me an error when I fill in the gaps: Assets/$$anonymous$$y Scripts/GUI/Inventory/Inventory_DatabaseEditor.cs(11,37): error CS1525: Unexpected symbol enum', expecting
identifier'
Your answer
![](https://koobas.hobune.stream/wayback/20220613160958im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I put a list of filenames into an editor menu? 2 Answers
Facebook popup hidden behind Unity Object in Chrome 2 Answers
Is it possible to create a windowless popup window? 1 Answer
Muting application during phonecall on Android(Call Popup) 3 Answers
How to add a popup GUI on a specific level before the Win popup? 1 Answer