- Home /
How do i place the GUI so it looks like a inventory?
for(var z = 0; z < MainInventory.Count; z++)
{
if(GUI.Button(Rect(Screen.width/2, Screen.height/2 + (50 * z), 50, 50), GUIContent(MainInventory[z].Icon, MainInventory[z].Name + "\n" + "Sell for " + MainInventory[z].Value + " coins")))
{
Coins += MainInventory[z].Value;
MainInventory.RemoveAt(z);
}
GUI.Label(Rect(Screen.width/2 + 150, Screen.height/2 + (50 * z), 300, 300), GUI.tooltip);
}
Looks like this:
[Item]
[Item]
[Item]
I want it to be like this:
[Item] [Item] [Item]
[Item] [Item] [Item]
[Item] [Item] [Item]
[Item] [Item] [Item]
Comment
Before you get to far down the OnGUI track consider updating to the latest release of Unity (4.6). The new UI is graphical, and may make some of your work easier.
Answer by fafase · Nov 28, 2014 at 07:48 PM
Do yourself a favor:
http://docs.unity3d.com/460/Documentation/Manual/script-GridLayoutGroup.html
Answer by YoungDeveloper · Nov 27, 2014 at 04:58 PM
Very optimized solution.
using UnityEngine;
public class Example : MonoBehaviour {
private byte WIDTH = 3;
private byte HEIGHT = 5;
private byte render_h = 0;
private byte render_w = 0;
private Rect slot = new Rect(0,0,32,32);
private void OnGUI(){
render_h = 0;
slot.y = 0;
for(; render_h < HEIGHT; render_h++){
render_w = 0;
for(; render_w < WIDTH; render_w++){
GUI.Box(slot, string.Empty);
slot.x += slot.width;
}
slot.x = 0;
slot.y += slot.height;
}
}
}
Your answer
Follow this Question
Related Questions
What are the differences between GUI.Label(Used to draw a texture) and GUI.DrawTexture? 0 Answers
How do adjust GUI.Label lineHeight? 1 Answer
GUI Label Width & Height 0 Answers
Shrink GUI 1 Answer