Create Variable if a condition is true/false ?

Actually i want to show some variables in inspector if condition1 is true & some other variables if condition1 is false, how to do it? thanks :slight_smile:

Custom editors is the only built-in way to do this.

Say you have something looking like this:

public class MyBehaviour : MonoBehaviour {
    
    public bool myBool;
    public int myInt;
}

And you only want to show the myInt in the inspector if myBool is true.

To do that, create a custom inspector:

using UnityEditor;

[CustomEditor(typeof(MyBehaviour))]
public class MyBehaviourEditor : Editor {

    public override void OnInspectorGUI() {
        //The target variable is the selected MyBehaviour.
        MyBehaviour mb = (MyBehaviour) target; 

        //Create a toggle for the bool variable.
        mb.myBool = EditorGUILayout.Toggle("MyBool", mb.myBool); 

        //Create an input field for the int only if the bool field is true.
        if(mb.myBool) {
            mb.myInt = EditorGUILayout.IntField("MyInt", mb.myInt);
        }
    }
}

Remember to put the editor class in the Editor folder, otherwise the UnityEditor namespace won’t be found.