Hi, so I just started writing a script and figured there was a lot of variables and would really like to use a dropdown menu so is there a way to make a dropdown menu in inspecor how? Code (CSharp): public bool isTrigByPlayerCOL; //menu 1 - item 1 public string playerTag = "Player"; [Space] public bool isTrigByOBJ; //menu 1 - item 2 public GameObject trigByOBJ; [Space] public bool isTrigByTrig; //menu 1 - item 3 [Space] [Header("What to do")] [Space] public bool enable_disable_GO = false; //menu 2 - item 1 public GameObject GO_ToDisab; public float disable_enable_after = 0f; [Space] public bool rotateOBJ = false; //menu 2 - item 2 public GameObject OBJ_toRotate; public char rotationAxis; public float rotateBy = 0; ......
http://answers.unity3d.com/questions/458987/dropdownlist-with-string-array-in-editor-inspector.html Maybe that will help. UnityEvents and enum are 2 that I can think of off hand that give you a dropdown menu by default. Customize your class anyway you'd like: https://docs.unity3d.com/ScriptReference/PropertyDrawer.html Says for Unity 4 but imagine it's mostly still relevant: https://blogs.unity3d.com/2012/09/07/property-drawers-in-unity-4/
I stumbled on this propertydrawer implementation for building a dropdown from any array of strings. After following the comment on the bottom, it worked great.
It's all right to start with a lot of public variables, but once you get them figured out, it's better to make them private so they aren't accidentally changed. Most of those bools, for instance, might be nice if you can see them for debugging, but once you get the program running well, you can make them private. There are reasons for making a list drop down, in which case you can use System.Serializable, or use an array, but just for your variables, I would just make a lot of them private, personally.
I had the same problem and was spending lots of time on it, too. The solution is to make a serializable class inside your script's class and make an instance of that Serializable class. If you don't make an instance of it, the variables will not show up in the Inspector. I read some of the Unity documentation for this, but they say to use the PropertyDrawer thing, which is probably more powerful, but this is just a simpler, and possibly easier solution. With the instance, just get all your variables from that instance. Here's an example: Code (CSharp): using System; //Needed for [Serializable] using UnityEngine; public class ScriptClass : MonoBehaviour { [Serializable] public class VariableHolder { public bool var1; public float var2 = 150f; public float var3 = 25f; } public VariableHolder instance = new VariableHolder(); //This is what makes the dropdown menu appear in the Inspector. It will have a dropdown arrow and the name of the instance. //Then, you would just reference the variables by saying float hi = instance.var2; for example }