# Toggle

> Makes a toggle.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.7/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

## Toggle(Rect, bool)

Makes a toggle.

```csharp
public static bool Toggle(Rect position, bool value)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the toggle.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): The shown state of the toggle.

### Returns

| Type                                                          | Description                       |
| ------------------------------------------------------------- | --------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | The selected state of the toggle. |

### Remarks

![EditorGUIToggle (Toggle)](/api/media?file=/engine/6000.7/media/images/EditorGUIToggle.png)

*Toggle control in an Editor Window.*

### Examples

```csharp
// Use a toggle button to show/hide a button that can close the window.
using UnityEngine;
using UnityEditor;

class EditorGUIToggle : EditorWindow
{
    bool showClose =  true;

    [MenuItem("Examples/EditorGUI Toggle usage")]
    static void Init()
    {
        EditorGUIToggle window = (EditorGUIToggle)GetWindow(typeof(EditorGUIToggle), true, "My Empty Window");
        window.Show();
    }

    void OnGUI()
    {
        showClose = EditorGUI.Toggle(new Rect(0, 5, position.width, 20),
            "Show Close Button",
            showClose);
        if (showClose)
            if (GUI.Button(new Rect(0, 25, position.width, 100), "Close Window!"))
                this.Close();
    }
}
```

## Toggle(Rect, string, bool)

Makes a toggle.

```csharp
public static bool Toggle(Rect position, string label, bool value)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the toggle.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Optional label in front of the toggle.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): The shown state of the toggle.

### Returns

| Type                                                          | Description                       |
| ------------------------------------------------------------- | --------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | The selected state of the toggle. |

### Remarks

![EditorGUIToggle (Toggle)](/api/media?file=/engine/6000.7/media/images/EditorGUIToggle.png)

*Toggle control in an Editor Window.*

### Examples

```csharp
// Use a toggle button to show/hide a button that can close the window.
using UnityEngine;
using UnityEditor;

class EditorGUIToggle : EditorWindow
{
    bool showClose =  true;

    [MenuItem("Examples/EditorGUI Toggle usage")]
    static void Init()
    {
        EditorGUIToggle window = (EditorGUIToggle)GetWindow(typeof(EditorGUIToggle), true, "My Empty Window");
        window.Show();
    }

    void OnGUI()
    {
        showClose = EditorGUI.Toggle(new Rect(0, 5, position.width, 20),
            "Show Close Button",
            showClose);
        if (showClose)
            if (GUI.Button(new Rect(0, 25, position.width, 100), "Close Window!"))
                this.Close();
    }
}
```

## Toggle(Rect, bool, GUIStyle)

Makes a toggle.

```csharp
public static bool Toggle(Rect position, bool value, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the toggle.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): The shown state of the toggle.**** (\[GUIStyle]\(/engine/6000.7/script-reference/unityengine/guistyle)): Optional [GUIStyle](/engine/6000.7/script-reference/unityengine/guistyle.md).

### Returns

| Type                                                          | Description                       |
| ------------------------------------------------------------- | --------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | The selected state of the toggle. |

### Remarks

![EditorGUIToggle (Toggle)](/api/media?file=/engine/6000.7/media/images/EditorGUIToggle.png)

*Toggle control in an Editor Window.*

### Examples

```csharp
// Use a toggle button to show/hide a button that can close the window.
using UnityEngine;
using UnityEditor;

class EditorGUIToggle : EditorWindow
{
    bool showClose =  true;

    [MenuItem("Examples/EditorGUI Toggle usage")]
    static void Init()
    {
        EditorGUIToggle window = (EditorGUIToggle)GetWindow(typeof(EditorGUIToggle), true, "My Empty Window");
        window.Show();
    }

    void OnGUI()
    {
        showClose = EditorGUI.Toggle(new Rect(0, 5, position.width, 20),
            "Show Close Button",
            showClose);
        if (showClose)
            if (GUI.Button(new Rect(0, 25, position.width, 100), "Close Window!"))
                this.Close();
    }
}
```

## Toggle(Rect, string, bool, GUIStyle)

Makes a toggle.

```csharp
public static bool Toggle(Rect position, string label, bool value, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the toggle.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Optional label in front of the toggle.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): The shown state of the toggle.**** (\[GUIStyle]\(/engine/6000.7/script-reference/unityengine/guistyle)): Optional [GUIStyle](/engine/6000.7/script-reference/unityengine/guistyle.md).

### Returns

| Type                                                          | Description                       |
| ------------------------------------------------------------- | --------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | The selected state of the toggle. |

### Remarks

![EditorGUIToggle (Toggle)](/api/media?file=/engine/6000.7/media/images/EditorGUIToggle.png)

*Toggle control in an Editor Window.*

### Examples

```csharp
// Use a toggle button to show/hide a button that can close the window.
using UnityEngine;
using UnityEditor;

class EditorGUIToggle : EditorWindow
{
    bool showClose =  true;

    [MenuItem("Examples/EditorGUI Toggle usage")]
    static void Init()
    {
        EditorGUIToggle window = (EditorGUIToggle)GetWindow(typeof(EditorGUIToggle), true, "My Empty Window");
        window.Show();
    }

    void OnGUI()
    {
        showClose = EditorGUI.Toggle(new Rect(0, 5, position.width, 20),
            "Show Close Button",
            showClose);
        if (showClose)
            if (GUI.Button(new Rect(0, 25, position.width, 100), "Close Window!"))
                this.Close();
    }
}
```

## Toggle(Rect, GUIContent, bool)

Makes a toggle.

```csharp
public static bool Toggle(Rect position, GUIContent label, bool value)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the toggle.**** (\[GUIContent]\(/engine/6000.7/script-reference/unityengine/guicontent)): Optional label in front of the toggle.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): The shown state of the toggle.

### Returns

| Type                                                          | Description                       |
| ------------------------------------------------------------- | --------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | The selected state of the toggle. |

### Remarks

![EditorGUIToggle (Toggle)](/api/media?file=/engine/6000.7/media/images/EditorGUIToggle.png)

*Toggle control in an Editor Window.*

### Examples

```csharp
// Use a toggle button to show/hide a button that can close the window.
using UnityEngine;
using UnityEditor;

class EditorGUIToggle : EditorWindow
{
    bool showClose =  true;

    [MenuItem("Examples/EditorGUI Toggle usage")]
    static void Init()
    {
        EditorGUIToggle window = (EditorGUIToggle)GetWindow(typeof(EditorGUIToggle), true, "My Empty Window");
        window.Show();
    }

    void OnGUI()
    {
        showClose = EditorGUI.Toggle(new Rect(0, 5, position.width, 20),
            "Show Close Button",
            showClose);
        if (showClose)
            if (GUI.Button(new Rect(0, 25, position.width, 100), "Close Window!"))
                this.Close();
    }
}
```

## Toggle(Rect, GUIContent, bool, GUIStyle)

Makes a toggle.

```csharp
public static bool Toggle(Rect position, GUIContent label, bool value, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the toggle.**** (\[GUIContent]\(/engine/6000.7/script-reference/unityengine/guicontent)): Optional label in front of the toggle.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): The shown state of the toggle.**** (\[GUIStyle]\(/engine/6000.7/script-reference/unityengine/guistyle)): Optional [GUIStyle](/engine/6000.7/script-reference/unityengine/guistyle.md).

### Returns

| Type                                                          | Description                       |
| ------------------------------------------------------------- | --------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | The selected state of the toggle. |

### Remarks

![EditorGUIToggle (Toggle)](/api/media?file=/engine/6000.7/media/images/EditorGUIToggle.png)

*Toggle control in an Editor Window.*

### Examples

```csharp
// Use a toggle button to show/hide a button that can close the window.
using UnityEngine;
using UnityEditor;

class EditorGUIToggle : EditorWindow
{
    bool showClose =  true;

    [MenuItem("Examples/EditorGUI Toggle usage")]
    static void Init()
    {
        EditorGUIToggle window = (EditorGUIToggle)GetWindow(typeof(EditorGUIToggle), true, "My Empty Window");
        window.Show();
    }

    void OnGUI()
    {
        showClose = EditorGUI.Toggle(new Rect(0, 5, position.width, 20),
            "Show Close Button",
            showClose);
        if (showClose)
            if (GUI.Button(new Rect(0, 25, position.width, 100), "Close Window!"))
                this.Close();
    }
}
```
