Version: 2017.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

GUI.SelectionGrid

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static method SelectionGrid(position: Rect, selected: int, texts: string[], xCount: int): int;
public static int SelectionGrid(Rect position, int selected, string[] texts, int xCount);
public static method SelectionGrid(position: Rect, selected: int, images: Texture[], xCount: int): int;
public static int SelectionGrid(Rect position, int selected, Texture[] images, int xCount);
public static method SelectionGrid(position: Rect, selected: int, content: GUIContent[], xCount: int): int;
public static int SelectionGrid(Rect position, int selected, GUIContent[] content, int xCount);
public static method SelectionGrid(position: Rect, selected: int, texts: string[], xCount: int, style: GUIStyle): int;
public static int SelectionGrid(Rect position, int selected, string[] texts, int xCount, GUIStyle style);
public static method SelectionGrid(position: Rect, selected: int, images: Texture[], xCount: int, style: GUIStyle): int;
public static int SelectionGrid(Rect position, int selected, Texture[] images, int xCount, GUIStyle style);
public static method SelectionGrid(position: Rect, selected: int, contents: GUIContent[], xCount: int, style: GUIStyle): int;
public static int SelectionGrid(Rect position, int selected, GUIContent[] contents, int xCount, GUIStyle style);

Parameters

positionRectangle on the screen to use for the grid.
selectedThe index of the selected grid button.
textsAn array of strings to show on the grid buttons.
imagesAn array of textures on the grid buttons.
contentsAn array of text, image and tooltips for the grid button.
xCountHow many elements to fit in the horizontal direction. The controls will be scaled to fit unless the style defines a fixedWidth to use.
styleThe style to use. If left out, the button style from the current GUISkin is used.

Returns

int The index of the selected button.

Description

Make a grid of buttons.

no example available in JavaScript
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); } }