- Home /
 
C# How to have a toggle
how do I have a GUILayout toggle so I can open and close a Rect with the toggle when ever I want to?
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by TonyLi · Jul 25, 2013 at 05:33 PM
Read the reference for GUILayout.Toggle: http://docs.unity3d.com/Documentation/ScriptReference/GUILayout.Toggle.html
You didn't specify what kind of rect. The example below displays a label in a rect if the toggle is ticked.
 private bool showRect = false;
 
 void OnGUI() {
     showRect = GUILayout.Toggle(showRect, "Show Rect");
     if (showRect) GUILayout.Label(new Rect(100,100,200,200), "My Rect");
 }
 
              Wow. I never knew about this! I've been using bools to toggle EVERYTHING including GUI all this time, thanks! +1
Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
UNET Health isn't syncing 1 Answer
how to find out if player hosted game 1 Answer
Multiplayer desynchronize when grabbing an object by code. 0 Answers