Search Unity

  1. Going to #UniteBerlin? Bring a buddy & get 25% off the 2nd ticket! More info here.
    Dismiss Notice
  2. Famed game designer and creator of The Sims, SimCIty, and Spore is looking for a 3D artist to join their team. Join the challenge.
    Dismiss Notice
  3. Unity 2017.4 has arrived! Read about it here.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. We've opened a new World Building sub-forum to faciltate all your world building discussions! Drop in and ask any ProBuilder, ProGrids, or PolyBrush questions.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Show/Hide Scriptable Object depending on bool value

Discussion in 'Extensions & OnGUI' started by mrCharli3, Apr 16, 2018 at 12:28 PM.

  1. mrCharli3


    Mar 22, 2017
    I want to show/hide some values depending on if a bool variable is set to true or false in the editor. I can do it with an int like this:

    Code (CSharp):
    1. public class MyScript : MonoBehaviour
    2. {
    3.    public bool flag;
    4.    public int i = 1;
    5. }
    6. [CustomEditor(typeof(MyScript))]
    7. public class MyScriptEditor : Editor
    8. {
    10. override public void OnInspectorGUI()
    11.    {
    12.      var myScript = target as MyScript;
    13.      myScript.flag = GUILayout.Toggle(myScript.flag, "Flag");
    15.      if(myScript.flag)
    16.        myScript.i = EditorGUILayout.IntSlider("I field:", myScript.i , 1 , 100);
    17.    }
    18. }
    I cannot find the correct EditorGUILayout component to use for a scriptable object. How can I do this?