- Home /
Unity GUI multiple grids?
Hello, I have 24 buttons in a grid that the player can select and use how they want, you are able to bring this grid up by pressing a button called "Items1". However I would like to have more buttons but not add them to this specific grid. Instead have another button saying "Items2" that when clicked brings up another grid of different buttons. I have already tried to do this and failed miserably, can someone help me out?
This is my script so far,
var selGridInt : int = 0;
var selStrings : String[] = ["Grid 1", "Grid 2", "Grid 3", "Grid 4"];
var showInventory = false;
public var prefabObject : GameObject;
private var offset : Vector3;
private var fwd : Vector3;
private var clone : GameObject;
var unit : float = 1.0f;
var Sound : AudioClip;
function Update () {
fwd = transform.TransformDirection(Vector3.forward) * unit;
offset = transform.position + fwd;
if(Input.GetKeyDown(KeyCode.E)){
audio.PlayOneShot(Sound);
clone = Instantiate(prefabObject, offset, transform.rotation);
}
if(Input.GetKeyDown(KeyCode.I)){
showInventory = !showInventory;
}
}
var showItems1 = false;
function OnGUI () {
if(showInventory == true){
GUI.Box (Rect (180,40,340,380), "Menu");
if (GUI.Button (Rect (220,60,80,20), "Items1")) {
showItems1 = !showItems1;
}
if (GUI.Button (Rect (400,60,100,20), "Quit Game")) {
Application.LoadLevel(0);
}
if(showItems1 == true){
selGridInt = GUI.SelectionGrid (Rect (200, 100, 300, 300), selGridInt, selStrings, 2);
if((selGridInt == 0) && showInventory == true){
prefabObject = (Resources.Load("square wall2"));
}
if((selGridInt == 1) && showInventory == true){
prefabObject = (Resources.Load("wooden plank2"));
}
if((selGridInt == 2) && showInventory == true){
prefabObject = (Resources.Load("rectangular wall"));
}
if((selGridInt == 3) && showInventory == true){
prefabObject = (Resources.Load("ladder"));
}
if((selGridInt == 4) && showInventory == true){
prefabObject = (Resources.Load("door"));
}
if((selGridInt == 5) && showInventory == true){
prefabObject = (Resources.Load("floor"));
}
if((selGridInt == 6) && showInventory == true){
prefabObject = (Resources.Load("window frame"));
}
if((selGridInt == 7) && showInventory == true){
prefabObject = (Resources.Load("wall light"));
}
if((selGridInt == 8) && showInventory == true){
prefabObject = (Resources.Load("fence"));
}
if((selGridInt == 9) && showInventory == true){
prefabObject = (Resources.Load("glass wall"));
}
if((selGridInt == 10) && showInventory == true){
prefabObject = (Resources.Load("column"));
}
if((selGridInt == 11) && showInventory == true){
prefabObject = (Resources.Load("half wall up"));
}
if((selGridInt == 12) && showInventory == true){
prefabObject = (Resources.Load("chair"));
}
if((selGridInt == 13) && showInventory == true){
prefabObject = (Resources.Load("table"));
}
if((selGridInt == 14) && showInventory == true){
prefabObject = (Resources.Load("half wall down"));
}
if((selGridInt == 15) && showInventory == true){
prefabObject = (Resources.Load("platform"));
}
if((selGridInt == 16) && showInventory == true){
prefabObject = (Resources.Load("cone"));
}
if((selGridInt == 17) && showInventory == true){
prefabObject = (Resources.Load("glass floor roof"));
}
if((selGridInt == 18) && showInventory == true){
prefabObject = (Resources.Load("???"));
}
if((selGridInt == 19) && showInventory == true){
prefabObject = (Resources.Load("???"));
}
if((selGridInt == 20) && showInventory == true){
prefabObject = (Resources.Load("???"));
}
if((selGridInt == 21) && showInventory == true){
prefabObject = (Resources.Load("lamp"));
}
if((selGridInt == 22) && showInventory == true){
prefabObject = (Resources.Load("plant"));
}
if((selGridInt == 23) && showInventory == true){
prefabObject = (Resources.Load("big ass block"));
}
}
}
}
you want another keypress that brings up a different grid? i dont understand the gui functionality.
Yeah, if a different button is pressed a different grid shows up which contains more objects.
Your answer
Follow this Question
Related Questions
Using GUI Button to activate script instances 1 Answer
controlling GUI.Button state 1 Answer
GUI grid of buttons issue. 1 Answer