Unity3d Hide/Show Inspector Variables with Bool

//BoolExample.cs using UnityEngine; using System.Collections; public class BoolExample : MonoBehaviour { public bool boolExample; public bool boolExampleToggle; } //Create in Assets/Editor //BoolExampleEditor.cs using UnityEditor; using UnityEngine; [CustomEditor( typeof(BoolExample) ), CanEditMultipleObjects] public class BoolExampleEditor : Editor { public SerializedProperty boolExample_Property, boolExampleToggle_Property; void OnEnable(){ boolExample_Property = serializedObject.FindProperty( "boolExample" ); boolExampleToggle_Property = serializedObject.FindProperty( "boolExampleToggle" ); } public override void OnInspectorGUI(){ serializedObject.Update(); EditorGUILayout.PropertyField( boolExample_Property ); bool _boolExample = ( bool )boolExample_Property.boolValue; if ( _boolExample ){ EditorGUILayout.PropertyField( boolExampleToggle_Property, new GUIContent("boolExampleToggle") ); } serializedObject.ApplyModifiedProperties(); } }
unity3d-hideshow-inspector-variables-with-bool