- Home /
GUI Labels Overlap
I am trying to have gui labels display various statistical elements. I seem to be missing something about changing the position of these, most of them are overlapping and their position will not change. And when I was changing the position on the first ones, I had to restart Unity to see some of the updates.
Here is the scripts (the important part anyway)
var labelPos1 : Rect = Rect(10,16,100,20);
var labelPos2 : Rect = Rect(10,32,100,40);
var labelPos3 : Rect = Rect(100,16,200,20);
var labelPos4 : Rect = Rect(100,32,200,40);
var labelPos5 : Rect = Rect(10,48,100,20);
var labelPos6 : Rect = Rect(10,64,100,40);
var labelPos7 : Rect = Rect(200,48,300,20);
var labelPos8 : Rect = Rect(200,64,300,40);
function OnGUI()
{
GUI.Label(labelPos1, "Strength:" + strength);
GUI.Label(labelPos2, "Dexterity:" + dexterity);
GUI.Label(labelPos3, "Health:" + healthCurrent);
GUI.Label(labelPos4, "Stamina:" + staminaCurrent);
GUI.Label(labelPos5, "S:" + strength);
GUI.Label(labelPos6, "D:" + dexterity);
GUI.Label(labelPos7, "H:" + healthCurrent);
GUI.Label(labelPos8, "S:" + staminaCurrent);
}
This code seems alright. Could you upload a screenshot ?
Answer by ngs6_16 · Jun 13, 2012 at 02:46 PM
I figured it out literally 2 minutes after I posted the question.
The problem was for some reason I needed to make the variables private.
Answer by hathol · Jun 12, 2012 at 07:36 PM
Not sure about the problem with them not changing position, since the function is fine. However, the overlapping is easily explained:
The rect is defined as (x,y,width,height). So if your first label is at y=16 and has a height of 20, its lower bounds extend to y=36. Since your label 2 starts at y=32 it's overlapping 4 pixels. Similar for the rest of your labels.
But unless he is using a skin, the label doesn't have a background so the overlapping would be visible only if the letters overlaps
Thats not the problem I was having. But i did need to know the exact details on what the x,y,width,height was so thank you very much for that! I did figure it out though. I needed the variables to be private for some reason... maybe something to do with pragma strict.
Your answer
Follow this Question
Related Questions
GUI Label Size and Position Changes With Resolution 2 Answers
Trying to draw GUI.Label() at object position 5 Answers
How do I position a GUI Label over an object? 1 Answer
Auto positioning GUI Labels? 0 Answers
Gui label variable as a string.. 1 Answer