Search Unity

Question How to disable specific one control in editor window using toggle and GUI.enabled ?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Chocolade, Jul 8, 2022.

  1. Chocolade

    Chocolade

    Joined:
    Jun 19, 2013
    Posts:
    933
    Depending on the allObjects toggle i want to enabled false/true only the transform ObjectField but it's enabling false/true all the other controls after the ObjectField too.

    Code (csharp):
    1.  
    2.  private void OnGUI()
    3.     {
    4.         GUILayout.Space(20);
    5.  
    6.         allObjects = EditorGUILayout.Toggle("Include Children", allObjects);
    7.  
    8.         GUILayout.Space(20);
    9.  
    10.         if(allObjects)
    11.         {
    12.             GUI.enabled = false;
    13.         }
    14.         else
    15.         {
    16.             GUI.enabled = true;
    17.         }
    18.         transform = EditorGUILayout.ObjectField("Transform to get childs", transform, typeof(Transform), true) as Transform;
    19.