Unity Custom Editor

Hi,

I’m very new to Unity Custom Editor, this is the problem, I want to display a variable only if another is set to true, someone know how can I achieve that?

let’s say I have:

public bool canStackJump;
public int howManyJumpsCanStack;

I want to hide “howManyJumpsCanStack” from the inspector unless “canStackJump” is set to true.
any ideas?

I’m working with c#, thanks in advanced.

using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(PlayerController))]
[CanEditMultipleObjects]
public class PlayerControllerUnityEditor : Editor {



    SerializedProperty
        canStackJump,
        howManyJumpStacks;
   
    void OnEnable() {
        // Setup serialized property
        canStackJump = serializedObject.FindProperty ("canStackJump");
    }

    public override void OnInspectorGUI() {
        DrawDefaultInspector();
        serializedObject.Update ();

        if (canStackJump.boolValue) {
            EditorGUILayout.LabelField("Level", canStackJump.boolValue.ToString());
            //Somthing here to display the other property//
        }
        serializedObject.ApplyModifiedProperties ();
    }
}

Nevermind, I was able to do it, here’s the code :

using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(PlayerController))]
[CanEditMultipleObjects]
public class PlayerControllerUnityEditor : Editor {

    PlayerController _playerController;
    bool stackJump;

   
    void OnEnable() {
        // Setup serialized property
        _playerController = (PlayerController)target;


    }

    public override void OnInspectorGUI() {
        DrawDefaultInspector();
        //base.OnInspectorGUI ();
//        EditorGUILayout.BeginVertical ();
//        GUILayout.Label ("Player Properties");
//        EditorGUILayout.BeginHorizontal ();
//        GUILayout.Label ("JumpForce");
//        _playerController.jumpForce = EditorGUILayout.Slider(_playerController,
//        EditorGUILayout.EndVertical ();
        EditorGUILayout.BeginFadeGroup (1);
            stackJump = EditorGUILayout.BeginToggleGroup ("Stack Jump",stackJump);
            EditorGUILayout.BeginHorizontal ();
                _playerController.canStackJump = stackJump;
            EditorGUILayout.EndHorizontal ();
            EditorGUILayout.BeginVertical ();
                if (_playerController.canStackJump) {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("How Many Jump Stacks");
                    _playerController.howManyJumpStacks = EditorGUILayout.IntSlider(_playerController.howManyJumpStacks,1,5);
                    EditorGUILayout.EndHorizontal();
                    //Somthing here to display the other property//
                }
            EditorGUILayout.EndVertical ();
            EditorGUILayout.EndToggleGroup ();
        EditorGUILayout.EndFadeGroup ();

        //base.OnInspectorGUI ();

        //serializedObject.ApplyModifiedProperties ();
        if (GUI.changed) {
            EditorUtility.SetDirty(_playerController);       
        }
    }
}