- Home /
Grid of GUILayout buttons?
How do I make a inventory style grid of GUILayoutButtons, my code only uses them horizontally, but, i do not use GUILayout.BeginHorizontal; What am I doing wrong, and how do I fix it?
Code:
 //Create a Area for the items.
         GUILayout.BeginArea (new Rect(5,100,420,240));
         int num = 0;
         foreach(Item it in InventoryItems){
 
             if(GUILayout.Button("Item "+ it.ItemName,GUILayout.Width(40),GUILayout.Height(40))){
                 Debug.Log("Item id: " + num + " is the new selected item.");
                 SelectedItemInt = num;
                 SelectedItemItem = it;
             }
             num++;
         }
 
         GUILayout.EndArea ();
Answer by clunk47 · Jan 06, 2014 at 05:03 AM
Check out GUI.SelectionGrid, or do Begin and End for each set of buttons.
An example? I want it like the layout of a selection grid, but with buttons and GUILayout preferably.
There's an example on the page I linked you to.
 using UnityEngine;
 using System.Collections;
 
 public class Example : $$anonymous$$onoBehaviour 
 {
     public int selGridInt = 0;
     public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"};
 
     void OnGUI() 
     {
         selGridInt = GUILayout.SelectionGrid(selGridInt, selStrings, 2);
     }
 }
Just Begin and End GUI Area to your liking.
 using UnityEngine;
 using System.Collections;
 
 public class Example : $$anonymous$$onoBehaviour 
 {
     public int selGridInt = 0;
     public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"};
 
     void OnGUI() 
     {
         GUILayout.BeginArea(new Rect(Screen.width /2.5F, Screen.height /1.25F, 128, 256));
         selGridInt = GUILayout.SelectionGrid(selGridInt, selStrings, 2);
         GUILayout.EndArea();
     }
 }
Your answer
 
 
             Follow this Question
Related Questions
Something like GUI.Table or a Grid? 5 Answers
Why can't I get my tooltip to show only when there is a tooltip set? 2 Answers
GUI.Window error. InvalidOperationException: Hashtable.Enumerator: snapshot out of sync. 0 Answers
know GUILayout current screen position 2 Answers
"'UnityEngine.GUI.DoTextField' is inaccessible due to its protection level." 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                