I need a little help figuring out how exactly I can setup a basic group of buttons. Right now they spawn ontop of one another and was testing out some GUILayouts and such but with no luck. Trying to create a 6 x 10 button grid with a scrollview as well. I guess I just have no idea how to space everything out depending on how many objects are in my list.
function OnGUI () {
for(var x = 0; x < myList.Count; x++) {
if (GUI.Button(Rect(Screen.width/2,Screen.height/2,64,64), GUIContent (myList[x]._icon, "test ")) {
}
}
}
Didn't seem to work. Is there anyway to do something like this. function OnGUI () { for(var x = 0; x < myList.Count && x < 6; x++) { for(var z = 0; z < myList.Count; z++) { if (GUI.Button(Rect(Screen.width/2 + (64 * z),Screen.height/2 + (64 * x),64,64), GUIContent (myList[x]._icon, "test ")) { } } } } The only problem is that it creates rows of the same button acting as one button. So how would I set the Count limit for each row. Like a max of 6 instead of creating extra non functioning buttons?
– jessee03var counter = 0; for(var x = 0; x < 6 && counter < myList.Count; x++) { for(var z = 0; z < 10; z++) { if (GUI.Button(Rect(Screen.width/2 + (64 * z),Screen.height/2 + (64 * x),64,64), GUIContent (myList[x]._icon, "test ")) { counter++; if(counter >= myList.Count) break; } } }
– whydoidoitI tried that out but with no luck. It just creates a giant grid of buttons even if there's only 10 items
– jessee03No it doesn't if I'd put in the right closing brace "}"
– whydoidoitvar counter = 0; for(var x = 0; x < 6 && counter < myList.Count; x++) { for(var z = 0; z < 10; z++) { if (GUI.Button(Rect(Screen.width/2 + (64 * z),Screen.height/2 + (64 * x),64,64), GUIContent (myList[x]._icon, "test "))) { //Do something } counter++; if(counter >= myList.Count) break; } } }
– whydoidoit