Hello! I parse "items" from DB (names, id, description, icon) from inventory. In inventory I write cycle which make buttons and then icons. I want icons grid. I don't know how to write this. In real: All right: P.S. Sorry for my bad English
Something like this will do the job. Code (csharp): int buttonWidth = 50; int buttonHeight = 50; int offset = 5; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columnCount; j++) { if (GUI.Button(new Rect(j * buttonWidth + offset, i * buttonHeight + offset, buttonWidth, buttonHeight), "Label")) { // Do something } } } Google nested loops and grids.
It work a bit wrong. I parse items from BD, and show them in cycle via "foreach". I use this. Code (csharp): for (int i = 0; i < 5; i++){ for (int j = 0; j < 7; j++) { foreach(string img in image){ if(img=="purseico")icon=purse_ico; if(img=="noneico")icon=none_ico; GUI.Button (new Rect(j * buttonWidth + offset, i * buttonHeight + offset, buttonWidth, buttonHeight), icon); } } } Buttons are really located grid. But showed 7 buttons instead 1 button in one slot, since their DB 7. Screen:
I corrected this problem Code (csharp): foreach(string img in image){ if(img=="purseico")icon=purse_ico; if(img=="noneico")icon=none_ico; if(j<7){ j++; if(j==7&i<5){ j = 0; i++; } } GUI.Button (new Rect(j * buttonWidth + offset, i * buttonHeight + offset, buttonWidth, buttonHeight), icon); } Thank you!