# SelectionGrid

> Make a grid of buttons.

## Definition

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

## SelectionGrid(Rect, int, string\[], int)

Make a grid of buttons.

```csharp
public static int SelectionGrid(Rect position, int selected, string[] texts, int xCount)
```

### Parameters

**** (\[Rect]\(/engine/6000.5/script-reference/unityengine/rect)): Rectangle on the screen to use for the grid.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The index of the selected grid button.**** (\[string\[]]\(https\://learn.microsoft.com/dotnet/api/system.string)): An array of strings to show on the grid buttons.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): How many elements to fit in the horizontal direction. The controls will be scaled to fit unless the style defines a fixedWidth to use.

### Returns

| Type                                                       | Description                       |
| ---------------------------------------------------------- | --------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index of the selected button. |

### Examples

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

public class ExampleClass : MonoBehaviour
{
    public int selGridInt = 0;
    public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"};

    void OnGUI()
    {
        // use 2 elements in the horizontal direction
        selGridInt = GUI.SelectionGrid(new Rect(25, 25, 100, 30), selGridInt, selStrings, 2);
    }
}
```

## SelectionGrid(Rect, int, Texture\[], int)

Make a grid of buttons.

```csharp
public static int SelectionGrid(Rect position, int selected, Texture[] images, int xCount)
```

### Parameters

**** (\[Rect]\(/engine/6000.5/script-reference/unityengine/rect)): Rectangle on the screen to use for the grid.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The index of the selected grid button.**** (\[Texture\[]]\(/engine/6000.5/script-reference/unityengine/texture)): An array of textures on the grid buttons.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): How many elements to fit in the horizontal direction. The controls will be scaled to fit unless the style defines a fixedWidth to use.

### Returns

| Type                                                       | Description                       |
| ---------------------------------------------------------- | --------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index of the selected button. |

### Examples

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

public class ExampleClass : MonoBehaviour
{
    public int selGridInt = 0;
    public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"};

    void OnGUI()
    {
        // use 2 elements in the horizontal direction
        selGridInt = GUI.SelectionGrid(new Rect(25, 25, 100, 30), selGridInt, selStrings, 2);
    }
}
```

## SelectionGrid(Rect, int, GUIContent\[], int)

Make a grid of buttons.

```csharp
public static int SelectionGrid(Rect position, int selected, GUIContent[] content, int xCount)
```

### Parameters

**** (\[Rect]\(/engine/6000.5/script-reference/unityengine/rect)): Rectangle on the screen to use for the grid.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The index of the selected grid button.**** (\[GUIContent\[]]\(/engine/6000.5/script-reference/unityengine/guicontent)): **** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): How many elements to fit in the horizontal direction. The controls will be scaled to fit unless the style defines a fixedWidth to use.

### Returns

| Type                                                       | Description                       |
| ---------------------------------------------------------- | --------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index of the selected button. |

### Examples

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

public class ExampleClass : MonoBehaviour
{
    public int selGridInt = 0;
    public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"};

    void OnGUI()
    {
        // use 2 elements in the horizontal direction
        selGridInt = GUI.SelectionGrid(new Rect(25, 25, 100, 30), selGridInt, selStrings, 2);
    }
}
```

## SelectionGrid(Rect, int, string\[], int, GUIStyle)

Make a grid of buttons.

```csharp
public static int SelectionGrid(Rect position, int selected, string[] texts, int xCount, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.5/script-reference/unityengine/rect)): Rectangle on the screen to use for the grid.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The index of the selected grid button.**** (\[string\[]]\(https\://learn.microsoft.com/dotnet/api/system.string)): An array of strings to show on the grid buttons.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): How many elements to fit in the horizontal direction. The controls will be scaled to fit unless the style defines a fixedWidth to use.**** (\[GUIStyle]\(/engine/6000.5/script-reference/unityengine/guistyle)): The style to use. If left out, the `button` style from the current [GUISkin](/engine/6000.5/script-reference/unityengine/guiskin.md) is used.

### Returns

| Type                                                       | Description                       |
| ---------------------------------------------------------- | --------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index of the selected button. |

### Examples

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

public class ExampleClass : MonoBehaviour
{
    public int selGridInt = 0;
    public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"};

    void OnGUI()
    {
        // use 2 elements in the horizontal direction
        selGridInt = GUI.SelectionGrid(new Rect(25, 25, 100, 30), selGridInt, selStrings, 2);
    }
}
```

## SelectionGrid(Rect, int, Texture\[], int, GUIStyle)

Make a grid of buttons.

```csharp
public static int SelectionGrid(Rect position, int selected, Texture[] images, int xCount, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.5/script-reference/unityengine/rect)): Rectangle on the screen to use for the grid.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The index of the selected grid button.**** (\[Texture\[]]\(/engine/6000.5/script-reference/unityengine/texture)): An array of textures on the grid buttons.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): How many elements to fit in the horizontal direction. The controls will be scaled to fit unless the style defines a fixedWidth to use.**** (\[GUIStyle]\(/engine/6000.5/script-reference/unityengine/guistyle)): The style to use. If left out, the `button` style from the current [GUISkin](/engine/6000.5/script-reference/unityengine/guiskin.md) is used.

### Returns

| Type                                                       | Description                       |
| ---------------------------------------------------------- | --------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index of the selected button. |

### Examples

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

public class ExampleClass : MonoBehaviour
{
    public int selGridInt = 0;
    public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"};

    void OnGUI()
    {
        // use 2 elements in the horizontal direction
        selGridInt = GUI.SelectionGrid(new Rect(25, 25, 100, 30), selGridInt, selStrings, 2);
    }
}
```

## SelectionGrid(Rect, int, GUIContent\[], int, GUIStyle)

Make a grid of buttons.

```csharp
public static int SelectionGrid(Rect position, int selected, GUIContent[] contents, int xCount, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.5/script-reference/unityengine/rect)): Rectangle on the screen to use for the grid.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The index of the selected grid button.**** (\[GUIContent\[]]\(/engine/6000.5/script-reference/unityengine/guicontent)): An array of text, image and tooltips for the grid button.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): How many elements to fit in the horizontal direction. The controls will be scaled to fit unless the style defines a fixedWidth to use.**** (\[GUIStyle]\(/engine/6000.5/script-reference/unityengine/guistyle)): The style to use. If left out, the `button` style from the current [GUISkin](/engine/6000.5/script-reference/unityengine/guiskin.md) is used.

### Returns

| Type                                                       | Description                       |
| ---------------------------------------------------------- | --------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index of the selected button. |

### Examples

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

public class ExampleClass : MonoBehaviour
{
    public int selGridInt = 0;
    public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"};

    void OnGUI()
    {
        // use 2 elements in the horizontal direction
        selGridInt = GUI.SelectionGrid(new Rect(25, 25, 100, 30), selGridInt, selStrings, 2);
    }
}
```
