Search Unity

unity editor scripting: toggle

Discussion in 'Scripting' started by FeboGamedeveloper, Dec 2, 2020.

  1. FeboGamedeveloper

    FeboGamedeveloper

    Joined:
    Feb 2, 2014
    Posts:
    47
    I am working on unity editor for the first time, I have to add a simple toggle on the inspector, why does this code crash?

    Code (CSharp):
    1. public override void OnInspectorGUI()
    2.         {
    3.             GeometricPath path = target as GeometricPath;
    4.  
    5.             if (path.IsLerp)
    6.             {
    7.                 DrawDefaultInspector();
    8.             }
    9.             else
    10.             {
    11.                 EditorGUI.BeginChangeCheck();
    12.                 bool isLerp = EditorGUILayout.Toggle("isLerp", path.IsLerp);
    13.                 path.IsLerp = isLerp;
    14.             }
    15.         }
    16. }