- Home /
 
Draw more EditorGUILayout components?
I'm trying to Draw more components when I push a button in my inspector, but they are not drawing. What am I doing wrong?
 [CustomEditor(typeof(Stuff))]
 public class ExampleEditor : Editor
 {
 
 
         public override void OnInspectorGUI ()
         {
                 EditorGUILayout.LabelField ("Stuff");
                 if (GUILayout.Button ("Click")) {
                         EditorGUILayout.BeginHorizontal ();
                         EditorGUILayout.LabelField ("Ints");
                         EditorGUILayout.IntField (0);
                         EditorGUILayout.EndHorizontal ();
                         Repaint ();
                 }
         }
 }
 
               Thank you
               Comment
              
 
               
              What's the class definition for this?
This http://docs.unity3d.com/Documentation/ScriptReference/Editor.OnInspectorGUI.html looks like the "extends Editor" is required.
 
               Best Answer 
              
 
              Answer by fherbst · Sep 09, 2013 at 01:25 AM
GUILayout.Button("Click") will only be true in exactly the frame you click it. Do something like this:
        bool clicked = false;
        public override void OnInspectorGUI ()
        {
           EditorGUILayout.LabelField ("Stuff");
           if(GUILayout.Button ("Click"))
             clicked = !clicked; // button switches other stuff on and off
           if(clicked)
           {
                  EditorGUILayout.BeginHorizontal ();
                  EditorGUILayout.LabelField ("Ints");
                  numOne = EditorGUILayout.IntField (numOne);
                  EditorGUILayout.EndHorizontal ();
           }
        }
 
              Your answer