- Home /
OnGUI Labels affect different boxes?
Hi guys. I am currently working an a dialogue system. What I want to right now is having two different speech bubbles (one for each speaker) pop up. My approach is having two different boxes withing two different areas in two OnGUI functions. Then filling them with different text an options via labels and buttons.
All of this is KIND of working, but here is my problem: When one of the box has a label in it, the OTHER box (not containing a label) with two button options kind of pretends that the same label was there, too – and shows the buttons at that exact position where the label in the other box ends. The picture attached shows this problem.
Okay, so I understand that the label obviously affects both boxes, but I don't understand why – from my code it should be two different functions and areas and therefore different boxes?
I would be very happy for any ideas and solutions to my problem. I just want to be able to display different text and buttons independently in each boxes.
Thanks in advance!!
Here is the code:
void OnGUI(){
GUI.skin = dialogueGUI;
if (showDialogue&&dan01)
{
GameObject Dusty = GameObject.Find("Dusty");
PlayerControl playerControl = Dusty.GetComponent<PlayerControl>();
playerControl.canMove = false;
GameObject Dan = GameObject.Find("Dan");
GUI.BeginGroup (new Rect (700, 100, 500, 200));
GUI.Box (new Rect (0, 0, 0, 0), "");
if (dialogue1_1)
{
GUILayout.Label("Stop running around, will you? I am nervous enough already. This place gives me the creeps. I really wish this was over and done with. Like, yesterday.");
}
if (dialogue1_2a)
{
GUILayout.Label("Phew! Thought I was the only one.");
}
if (dialogue1_2b)
{
GUILayout.Label("Well, I'm glad at least one of us is enjoying herself.");
}
GUI.EndGroup ();
if (showDialogue&&dan01)
{
StartCoroutine(Wait());
GUI.BeginGroup (new Rect (220, 270, 500, 200));
GUI.Box (new Rect (0, 0, 0, 0), "");
if (dialogue1_1)
{
if (GUILayout.Button("Yeah, me too."))
{
dialogue1_1 = false;
dialogue1_2a = true;
}
if (GUILayout.Button("Really? I'm rather excited!"))
{
dialogue1_1 = false;
dialogue1_2b = true;
}
}
if (dialogue1_2a)
{
if (GUILayout.Button("Don't be too hard on yourself."))
{
dialogue1_2a = false;
dan01 = false;
dan01b = true;
showDialogue = false;
playerControl.canMove = true;
}
}
if (dialogue1_2b)
{
if (GUILayout.Button("You could really ease up a bit."))
{
dialogue1_2b = false;
dan01 = false;
dan01b = true;
showDialogue = false;
playerControl.canMove = true;
}
}
}
GUI.EndGroup ();
}
if (showDialogue&&dan01b){
GUI.BeginGroup (new Rect (Screen.width / 2 - 350, Screen.height / 2 + 150, 700, 140));
GUI.Box (new Rect (0,0,600,200), "");
GUILayout.Label("It's good to see you showing some compassion.");
GUI.EndGroup ();
}
}
Answer by Landern · Nov 22, 2013 at 03:13 PM
It appears you are mixing Layout Modes. For a break down click/follow this link(Unity - Layout Modes).
When i replaced some of your code using the Automatic layout(GUILayout) instead of fixed, replacing things like GUI.BeginGroup with GUILayout.BeginArea, etc. Your described problems went bye-bye. Give the documentation that i linked above a quick read and i think you will begin to understand what happened here.
Thank you so much; I really wasn't aware of me mixing up fixed and automatic layout. Great help!!
Your answer
Follow this Question
Related Questions
Why GUI Doesn't appears? 1 Answer
Trouble Positioning a GUILayout.Label, or as a button? 0 Answers
Making a text box appear after a certain gameObject is destroyed 0 Answers
Relate font size to screen size in GUISkin 2 Answers
How to find all GameObjects within a specific field of view/box 2 Answers