Okay, so I just started reading this: Unity - Manual: IMGUI Basics. But I can’t seem to understand what it’s talking about. (:
I need to make my box bigger and wider. So. Yes. All I need is someone to kind of tell me or explain to me how their coordinate, transform, whatever system works. (:
Here is the code I’m working with. (: Thanks!
void DrawJournalEntries()
{
GUI.BeginGroup (new Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));
// All rectangles are now adjusted to the group. (0,0) is the topleft corner of the group.
// We'll make a box so you can see where the group is on-screen.
GUI.Box (new Rect (0,0,100,100), "Group is here");
GUI.Button (new Rect (10,40,80,30), "Click me");
// End the group we started above. This is very important to remember!
GUI.EndGroup ();
}
2 Answers
2
If you need to make the box bigger, I’m going to assume it’s the GUI.Box()
So this is how you should do it.
GUI.Box(new Rect(20, 20, 100, 100), "Group is here")
//You have to put some numbers where you put the zeros. That's how you make the box visible.
You just need to know about Rect(). It has 4 parameters to pass.
- x coordinate of Starting point of GUI item
- y coordinate of Starting point of GUI item
- Width of the GUI Item
- Height of GUI Item.
so if you are creating a box which should be wide and big, you need to set higher width and height for it in Rect().
For e.g. GUI.Box(new Rect(20, 20, 500, 300), "Group is here");
This will create a box whose starting point is at (20,20) from left top corner of the screen. And if it is inside group then (20,20) from the group’s starting position. Width is 500 px and Height is 300 px. By increasing these value you can have bigger and wider box as much as you want.
This code will give you the bigger and wider box.
void OnGUI () {
GUI.BeginGroup (new Rect (Screen.width / 2 - 150, Screen.height / 2 - 150, 300, 300));
// All rectangles are now adjusted to the group. (0,0) is the topleft corner of the group.
// We'll make a box so you can see where the group is on-screen.
GUI.Box (new Rect (10,10,280,280), "Group is here");
GUI.Button (new Rect (10,40,80,30), "Click me");
// End the group we started above. This is very important to remember!
GUI.EndGroup ();
}
I've tried this, but the box becomes invisible when I do this... Well i think it gets cut off. I believe it has to do with the first Rect.. The BeginGroup one. What do you think? Also, I believe that the 20s do make it larger, but it's being cut off... Which is why I think the first one needs to be edited, but I'm unsure how to do this. (: It never seems to work! One last thing... When I put the 20s in, the box moves down towards the lower right hand side... How do I keep it centered? (: I'm sorry if this is a lot!
– WaterMinecraftNo it's not a lot. I made the mistake. The 20s are actually to move the box. So in order to center the box you must keep putting in values where the 20s are to get it the way you want it. The first 20 is for the x axis, and the second 20 is for the y axis. In order to make the box bigger smaller wider, taller, you have to change the 100s. Their axis are the same. I hope this helps, if you have any more questions just ask.
– FPSworriorThanks! (: It makes sense now that I know what this stuff means! Haha (:
– WaterMinecraft