# Toggle

> Make an on/off toggle button.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.IMGUIModule

## Toggle(bool, Texture, GUILayoutOption\[])

Make an on/off toggle button.

```csharp
public static bool Toggle(bool value, Texture image, params GUILayoutOption[] options)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Is the button on or off?**** (\[Texture]\(/engine/6000.7/script-reference/unityengine/texture)): [Texture](/engine/6000.7/script-reference/unityengine/texture.md) to display on the button.**** (\[GUILayoutOption\[]]\(/engine/6000.7/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style`.\
&#x20;[GUILayout.MaxHeight](/engine/6000.7/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.7/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.7/script-reference/unityengine/guilayout/expandheight.md)

### Returns

| Type                                                          | Description                  |
| ------------------------------------------------------------- | ---------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | The new value of the button. |

### Remarks

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

Toggle button in the Game View.

Additional Resources: [GUILayout.Width](/engine/6000.7/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.7/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.7/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.7/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.7/script-reference/unityengine/guilayout/minheight.md)

### Examples

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    // Draws 2 toggle controls, one with a text, the other with an image.
    Texture aTexture;

    bool toggleTxt = false;
    bool toggleImg = false;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Please assign a texture in the inspector.");
            return;
        }
        toggleTxt = GUILayout.Toggle(toggleTxt, "A Toggle text");
        toggleImg = GUILayout.Toggle(toggleImg, aTexture);
    }
}
```

## Toggle(bool, string, GUILayoutOption\[])

Make an on/off toggle button.

```csharp
public static bool Toggle(bool value, string text, params GUILayoutOption[] options)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Is the button on or off?**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to display on the button.**** (\[GUILayoutOption\[]]\(/engine/6000.7/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style`.\
&#x20;[GUILayout.MaxHeight](/engine/6000.7/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.7/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.7/script-reference/unityengine/guilayout/expandheight.md)

### Returns

| Type                                                          | Description                  |
| ------------------------------------------------------------- | ---------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | The new value of the button. |

### Remarks

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

Toggle button in the Game View.

Additional Resources: [GUILayout.Width](/engine/6000.7/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.7/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.7/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.7/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.7/script-reference/unityengine/guilayout/minheight.md)

### Examples

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    // Draws 2 toggle controls, one with a text, the other with an image.
    Texture aTexture;

    bool toggleTxt = false;
    bool toggleImg = false;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Please assign a texture in the inspector.");
            return;
        }
        toggleTxt = GUILayout.Toggle(toggleTxt, "A Toggle text");
        toggleImg = GUILayout.Toggle(toggleImg, aTexture);
    }
}
```

## Toggle(bool, GUIContent, GUILayoutOption\[])

Make an on/off toggle button.

```csharp
public static bool Toggle(bool value, GUIContent content, params GUILayoutOption[] options)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Is the button on or off?**** (\[GUIContent]\(/engine/6000.7/script-reference/unityengine/guicontent)): Text, image and tooltip for this button.**** (\[GUILayoutOption\[]]\(/engine/6000.7/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style`.\
&#x20;[GUILayout.MaxHeight](/engine/6000.7/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.7/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.7/script-reference/unityengine/guilayout/expandheight.md)

### Returns

| Type                                                          | Description                  |
| ------------------------------------------------------------- | ---------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | The new value of the button. |

### Remarks

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

Toggle button in the Game View.

Additional Resources: [GUILayout.Width](/engine/6000.7/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.7/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.7/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.7/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.7/script-reference/unityengine/guilayout/minheight.md)

### Examples

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    // Draws 2 toggle controls, one with a text, the other with an image.
    Texture aTexture;

    bool toggleTxt = false;
    bool toggleImg = false;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Please assign a texture in the inspector.");
            return;
        }
        toggleTxt = GUILayout.Toggle(toggleTxt, "A Toggle text");
        toggleImg = GUILayout.Toggle(toggleImg, aTexture);
    }
}
```

## Toggle(bool, Texture, GUIStyle, GUILayoutOption\[])

Make an on/off toggle button.

```csharp
public static bool Toggle(bool value, Texture image, GUIStyle style, params GUILayoutOption[] options)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Is the button on or off?**** (\[Texture]\(/engine/6000.7/script-reference/unityengine/texture)): [Texture](/engine/6000.7/script-reference/unityengine/texture.md) to display on the button.**** (\[GUIStyle]\(/engine/6000.7/script-reference/unityengine/guistyle)): The style to use. If left out, the `button` style from the current [GUISkin](/engine/6000.7/script-reference/unityengine/guiskin.md) is used.**** (\[GUILayoutOption\[]]\(/engine/6000.7/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style`.\
&#x20;[GUILayout.MaxHeight](/engine/6000.7/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.7/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.7/script-reference/unityengine/guilayout/expandheight.md)

### Returns

| Type                                                          | Description                  |
| ------------------------------------------------------------- | ---------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | The new value of the button. |

### Remarks

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

Toggle button in the Game View.

Additional Resources: [GUILayout.Width](/engine/6000.7/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.7/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.7/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.7/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.7/script-reference/unityengine/guilayout/minheight.md)

### Examples

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    // Draws 2 toggle controls, one with a text, the other with an image.
    Texture aTexture;

    bool toggleTxt = false;
    bool toggleImg = false;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Please assign a texture in the inspector.");
            return;
        }
        toggleTxt = GUILayout.Toggle(toggleTxt, "A Toggle text");
        toggleImg = GUILayout.Toggle(toggleImg, aTexture);
    }
}
```

## Toggle(bool, string, GUIStyle, GUILayoutOption\[])

Make an on/off toggle button.

```csharp
public static bool Toggle(bool value, string text, GUIStyle style, params GUILayoutOption[] options)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Is the button on or off?**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to display on the button.**** (\[GUIStyle]\(/engine/6000.7/script-reference/unityengine/guistyle)): The style to use. If left out, the `button` style from the current [GUISkin](/engine/6000.7/script-reference/unityengine/guiskin.md) is used.**** (\[GUILayoutOption\[]]\(/engine/6000.7/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style`.\
&#x20;[GUILayout.MaxHeight](/engine/6000.7/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.7/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.7/script-reference/unityengine/guilayout/expandheight.md)

### Returns

| Type                                                          | Description                  |
| ------------------------------------------------------------- | ---------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | The new value of the button. |

### Remarks

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

Toggle button in the Game View.

Additional Resources: [GUILayout.Width](/engine/6000.7/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.7/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.7/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.7/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.7/script-reference/unityengine/guilayout/minheight.md)

### Examples

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    // Draws 2 toggle controls, one with a text, the other with an image.
    Texture aTexture;

    bool toggleTxt = false;
    bool toggleImg = false;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Please assign a texture in the inspector.");
            return;
        }
        toggleTxt = GUILayout.Toggle(toggleTxt, "A Toggle text");
        toggleImg = GUILayout.Toggle(toggleImg, aTexture);
    }
}
```

## Toggle(bool, GUIContent, GUIStyle, GUILayoutOption\[])

Make an on/off toggle button.

```csharp
public static bool Toggle(bool value, GUIContent content, GUIStyle style, params GUILayoutOption[] options)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Is the button on or off?**** (\[GUIContent]\(/engine/6000.7/script-reference/unityengine/guicontent)): Text, image and tooltip for this button.**** (\[GUIStyle]\(/engine/6000.7/script-reference/unityengine/guistyle)): The style to use. If left out, the `button` style from the current [GUISkin](/engine/6000.7/script-reference/unityengine/guiskin.md) is used.**** (\[GUILayoutOption\[]]\(/engine/6000.7/script-reference/unityengine/guilayoutoption)): An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the `style`.\
&#x20;[GUILayout.MaxHeight](/engine/6000.7/script-reference/unityengine/guilayout/maxheight.md), [GUILayout.ExpandWidth](/engine/6000.7/script-reference/unityengine/guilayout/expandwidth.md), [GUILayout.ExpandHeight](/engine/6000.7/script-reference/unityengine/guilayout/expandheight.md)

### Returns

| Type                                                          | Description                  |
| ------------------------------------------------------------- | ---------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | The new value of the button. |

### Remarks

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

Toggle button in the Game View.

Additional Resources: [GUILayout.Width](/engine/6000.7/script-reference/unityengine/guilayout/width.md), [GUILayout.Height](/engine/6000.7/script-reference/unityengine/guilayout/height.md), [GUILayout.MinWidth](/engine/6000.7/script-reference/unityengine/guilayout/minwidth.md), [GUILayout.MaxWidth](/engine/6000.7/script-reference/unityengine/guilayout/maxwidth.md), [GUILayout.MinHeight](/engine/6000.7/script-reference/unityengine/guilayout/minheight.md)

### Examples

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    // Draws 2 toggle controls, one with a text, the other with an image.
    Texture aTexture;

    bool toggleTxt = false;
    bool toggleImg = false;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Please assign a texture in the inspector.");
            return;
        }
        toggleTxt = GUILayout.Toggle(toggleTxt, "A Toggle text");
        toggleImg = GUILayout.Toggle(toggleImg, aTexture);
    }
}
```
