# RepeatButton

> Make a button that is active as long as the user holds it down.

## Definition

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

## RepeatButton(Rect, string)

Make a button that is active as long as the user holds it down.

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

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the button.**** (\[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) | True when the users clicks the button. |

### Examples

```csharp
 // Draws 2 buttons, one with an image, and other with a text
 // Prints a message when they get clicked.

 // Prints a message when they get clicked.

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour
{
    public Texture btnTexture;

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

        if (GUI.RepeatButton(new Rect(10, 10, 50, 50), btnTexture))
            Debug.Log("Clicked the button with an image");

        if (GUI.RepeatButton(new Rect(10, 70, 50, 30), "Click"))
            Debug.Log("Clicked the button with text");
    }
}
```

## RepeatButton(Rect, Texture)

Make a button that is active as long as the user holds it down.

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

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the button.**** (\[Texture]\(/engine/6000.7/script-reference/unityengine/texture)): [Texture](/engine/6000.7/script-reference/unityengine/texture.md) to display on the button.

### Returns

| Type                                                          | Description                            |
| ------------------------------------------------------------- | -------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True when the users clicks the button. |

### Examples

```csharp
 // Draws 2 buttons, one with an image, and other with a text
 // Prints a message when they get clicked.

 // Prints a message when they get clicked.

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour
{
    public Texture btnTexture;

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

        if (GUI.RepeatButton(new Rect(10, 10, 50, 50), btnTexture))
            Debug.Log("Clicked the button with an image");

        if (GUI.RepeatButton(new Rect(10, 70, 50, 30), "Click"))
            Debug.Log("Clicked the button with text");
    }
}
```

## RepeatButton(Rect, GUIContent)

Make a button that is active as long as the user holds it down.

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

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the button.**** (\[GUIContent]\(/engine/6000.7/script-reference/unityengine/guicontent)): Text, image and tooltip for this button.

### Returns

| Type                                                          | Description                            |
| ------------------------------------------------------------- | -------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True when the users clicks the button. |

### Examples

```csharp
 // Draws 2 buttons, one with an image, and other with a text
 // Prints a message when they get clicked.

 // Prints a message when they get clicked.

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour
{
    public Texture btnTexture;

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

        if (GUI.RepeatButton(new Rect(10, 10, 50, 50), btnTexture))
            Debug.Log("Clicked the button with an image");

        if (GUI.RepeatButton(new Rect(10, 70, 50, 30), "Click"))
            Debug.Log("Clicked the button with text");
    }
}
```

## RepeatButton(Rect, string, GUIStyle)

Make a button that is active as long as the user holds it down.

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

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the button.**** (\[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.

### Returns

| Type                                                          | Description                            |
| ------------------------------------------------------------- | -------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True when the users clicks the button. |

### Examples

```csharp
 // Draws 2 buttons, one with an image, and other with a text
 // Prints a message when they get clicked.

 // Prints a message when they get clicked.

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour
{
    public Texture btnTexture;

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

        if (GUI.RepeatButton(new Rect(10, 10, 50, 50), btnTexture))
            Debug.Log("Clicked the button with an image");

        if (GUI.RepeatButton(new Rect(10, 70, 50, 30), "Click"))
            Debug.Log("Clicked the button with text");
    }
}
```

## RepeatButton(Rect, Texture, GUIStyle)

Make a button that is active as long as the user holds it down.

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

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the button.**** (\[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.

### Returns

| Type                                                          | Description                            |
| ------------------------------------------------------------- | -------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True when the users clicks the button. |

### Examples

```csharp
 // Draws 2 buttons, one with an image, and other with a text
 // Prints a message when they get clicked.

 // Prints a message when they get clicked.

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour
{
    public Texture btnTexture;

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

        if (GUI.RepeatButton(new Rect(10, 10, 50, 50), btnTexture))
            Debug.Log("Clicked the button with an image");

        if (GUI.RepeatButton(new Rect(10, 70, 50, 30), "Click"))
            Debug.Log("Clicked the button with text");
    }
}
```

## RepeatButton(Rect, GUIContent, GUIStyle)

Make a button that is active as long as the user holds it down.

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

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the button.**** (\[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.

### Returns

| Type                                                          | Description                            |
| ------------------------------------------------------------- | -------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True when the users clicks the button. |

### Examples

```csharp
 // Draws 2 buttons, one with an image, and other with a text
 // Prints a message when they get clicked.

 // Prints a message when they get clicked.

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour
{
    public Texture btnTexture;

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

        if (GUI.RepeatButton(new Rect(10, 10, 50, 50), btnTexture))
            Debug.Log("Clicked the button with an image");

        if (GUI.RepeatButton(new Rect(10, 70, 50, 30), "Click"))
            Debug.Log("Clicked the button with text");
    }
}
```
