# Toggle

> Make an on/off toggle button.

## Definition

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

## Toggle(Rect, bool, string)

Make an on/off toggle button.

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

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to use for the button.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Is this button on or off?**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to display on the button.

### Returns

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

### Examples

```csharp
// Draws 2 toggle controls, one with a text, the other with an image.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Texture aTexture;

    private bool toggleTxt = false;
    private bool toggleImg = false;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Please assign a texture in the inspector.");
            return;
        }

        toggleTxt = GUI.Toggle(new Rect(10, 10, 100, 30), toggleTxt, "A Toggle text");
        toggleImg = GUI.Toggle(new Rect(10, 50, 50, 50), toggleImg, aTexture);
    }
}
```

## Toggle(Rect, bool, Texture)

Make an on/off toggle button.

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

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to use for the button.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Is this button on or off?**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/texture)): [Texture](/engine/6000.6/script-reference/unityengine/texture.md) to display on the button.

### Returns

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

### Examples

```csharp
// Draws 2 toggle controls, one with a text, the other with an image.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Texture aTexture;

    private bool toggleTxt = false;
    private bool toggleImg = false;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Please assign a texture in the inspector.");
            return;
        }

        toggleTxt = GUI.Toggle(new Rect(10, 10, 100, 30), toggleTxt, "A Toggle text");
        toggleImg = GUI.Toggle(new Rect(10, 50, 50, 50), toggleImg, aTexture);
    }
}
```

## Toggle(Rect, bool, GUIContent)

Make an on/off toggle button.

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

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to use for the button.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Is this button on or off?**** (\[GUIContent]\(/engine/6000.6/script-reference/unityengine/guicontent)): Text, image and tooltip for this button.

### Returns

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

### Examples

```csharp
// Draws 2 toggle controls, one with a text, the other with an image.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Texture aTexture;

    private bool toggleTxt = false;
    private bool toggleImg = false;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Please assign a texture in the inspector.");
            return;
        }

        toggleTxt = GUI.Toggle(new Rect(10, 10, 100, 30), toggleTxt, "A Toggle text");
        toggleImg = GUI.Toggle(new Rect(10, 50, 50, 50), toggleImg, aTexture);
    }
}
```

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

Make an on/off toggle button.

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

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to use for the button.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Is this button on or off?**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to display on the button.**** (\[GUIStyle]\(/engine/6000.6/script-reference/unityengine/guistyle)): The style to use. If left out, the `toggle` style from the current [GUISkin](/engine/6000.6/script-reference/unityengine/guiskin.md) is used.

### Returns

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

### Examples

```csharp
// Draws 2 toggle controls, one with a text, the other with an image.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Texture aTexture;

    private bool toggleTxt = false;
    private bool toggleImg = false;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Please assign a texture in the inspector.");
            return;
        }

        toggleTxt = GUI.Toggle(new Rect(10, 10, 100, 30), toggleTxt, "A Toggle text");
        toggleImg = GUI.Toggle(new Rect(10, 50, 50, 50), toggleImg, aTexture);
    }
}
```

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

Make an on/off toggle button.

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

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to use for the button.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Is this button on or off?**** (\[Texture]\(/engine/6000.6/script-reference/unityengine/texture)): [Texture](/engine/6000.6/script-reference/unityengine/texture.md) to display on the button.**** (\[GUIStyle]\(/engine/6000.6/script-reference/unityengine/guistyle)): The style to use. If left out, the `toggle` style from the current [GUISkin](/engine/6000.6/script-reference/unityengine/guiskin.md) is used.

### Returns

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

### Examples

```csharp
// Draws 2 toggle controls, one with a text, the other with an image.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Texture aTexture;

    private bool toggleTxt = false;
    private bool toggleImg = false;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Please assign a texture in the inspector.");
            return;
        }

        toggleTxt = GUI.Toggle(new Rect(10, 10, 100, 30), toggleTxt, "A Toggle text");
        toggleImg = GUI.Toggle(new Rect(10, 50, 50, 50), toggleImg, aTexture);
    }
}
```

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

Make an on/off toggle button.

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

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to use for the button.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Is this button on or off?**** (\[GUIContent]\(/engine/6000.6/script-reference/unityengine/guicontent)): Text, image and tooltip for this button.**** (\[GUIStyle]\(/engine/6000.6/script-reference/unityengine/guistyle)): The style to use. If left out, the `toggle` style from the current [GUISkin](/engine/6000.6/script-reference/unityengine/guiskin.md) is used.

### Returns

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

### Examples

```csharp
// Draws 2 toggle controls, one with a text, the other with an image.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Texture aTexture;

    private bool toggleTxt = false;
    private bool toggleImg = false;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Please assign a texture in the inspector.");
            return;
        }

        toggleTxt = GUI.Toggle(new Rect(10, 10, 100, 30), toggleTxt, "A Toggle text");
        toggleImg = GUI.Toggle(new Rect(10, 50, 50, 50), toggleImg, aTexture);
    }
}
```

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

Make an on/off toggle button.

```csharp
public static bool Toggle(Rect position, int id, bool value, GUIContent content, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.6/script-reference/unityengine/rect)): Rectangle on the screen to use for the button.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): **** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Is this button on or off?**** (\[GUIContent]\(/engine/6000.6/script-reference/unityengine/guicontent)): Text, image and tooltip for this button.**** (\[GUIStyle]\(/engine/6000.6/script-reference/unityengine/guistyle)): The style to use. If left out, the `toggle` style from the current [GUISkin](/engine/6000.6/script-reference/unityengine/guiskin.md) is used.

### Returns

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

### Examples

```csharp
// Draws 2 toggle controls, one with a text, the other with an image.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Texture aTexture;

    private bool toggleTxt = false;
    private bool toggleImg = false;

    void OnGUI()
    {
        if (!aTexture)
        {
            Debug.LogError("Please assign a texture in the inspector.");
            return;
        }

        toggleTxt = GUI.Toggle(new Rect(10, 10, 100, 30), toggleTxt, "A Toggle text");
        toggleImg = GUI.Toggle(new Rect(10, 50, 50, 50), toggleImg, aTexture);
    }
}
```
