# TextField

> Make a single-line text field where the user can edit a string.

## Definition

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

## TextField(Rect, string)

Make a single-line text field where the user can edit a string.

```csharp
public static string TextField(Rect position, string text)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the text field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to edit. The return value of this function should be assigned back to the string as shown in the example.

### Returns

| Type                                                           | Description        |
| -------------------------------------------------------------- | ------------------ |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The edited string. |

### Examples

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public string stringToEdit = "Hello World";

    void OnGUI()
    {
        // Make a text field that modifies stringToEdit.
        stringToEdit = GUI.TextField(new Rect(10, 10, 200, 20), stringToEdit, 25);
    }
}
```

## TextField(Rect, string, int)

Make a single-line text field where the user can edit a string.

```csharp
public static string TextField(Rect position, string text, int maxLength)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the text field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to edit. The return value of this function should be assigned back to the string as shown in the example.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The maximum length of the string. If left out, the user can type for ever and ever.

### Returns

| Type                                                           | Description        |
| -------------------------------------------------------------- | ------------------ |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The edited string. |

### Examples

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public string stringToEdit = "Hello World";

    void OnGUI()
    {
        // Make a text field that modifies stringToEdit.
        stringToEdit = GUI.TextField(new Rect(10, 10, 200, 20), stringToEdit, 25);
    }
}
```

## TextField(Rect, string, GUIStyle)

Make a single-line text field where the user can edit a string.

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

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the text field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to edit. The return value of this function should be assigned back to the string as shown in the example.**** (\[GUIStyle]\(/engine/6000.7/script-reference/unityengine/guistyle)): The style to use. If left out, the `textField` style from the current [GUISkin](/engine/6000.7/script-reference/unityengine/guiskin.md) is used.

### Returns

| Type                                                           | Description        |
| -------------------------------------------------------------- | ------------------ |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The edited string. |

### Examples

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public string stringToEdit = "Hello World";

    void OnGUI()
    {
        // Make a text field that modifies stringToEdit.
        stringToEdit = GUI.TextField(new Rect(10, 10, 200, 20), stringToEdit, 25);
    }
}
```

## TextField(Rect, string, int, GUIStyle)

Make a single-line text field where the user can edit a string.

```csharp
public static string TextField(Rect position, string text, int maxLength, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): Rectangle on the screen to use for the text field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text to edit. The return value of this function should be assigned back to the string as shown in the example.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The maximum length of the string. If left out, the user can type for ever and ever.**** (\[GUIStyle]\(/engine/6000.7/script-reference/unityengine/guistyle)): The style to use. If left out, the `textField` style from the current [GUISkin](/engine/6000.7/script-reference/unityengine/guiskin.md) is used.

### Returns

| Type                                                           | Description        |
| -------------------------------------------------------------- | ------------------ |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The edited string. |

### Examples

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public string stringToEdit = "Hello World";

    void OnGUI()
    {
        // Make a text field that modifies stringToEdit.
        stringToEdit = GUI.TextField(new Rect(10, 10, 200, 20), stringToEdit, 25);
    }
}
```
