- Home /
Relative GUI positioning and Pixel Inset/Offset conversion
I’m trying to position GUI like on the picture below.
Basically, I need each element to be next to the one above it regardless of screen resolution and the top element (GUIText saying “Jumps Left: 3”) at a fixed distance from Screen.height / 2.0.
The reason I can’t figure it out is that GUIText has different properties than GUITexture. Namely, it has Pixel Offset whereas GUITexture has Pixel Inset. What’s the difference between the two and is there a way to convert one into the other?
Answer by Seizure · Jul 31, 2013 at 08:36 PM
Can you not just make everything relative to the Rect before it?
For example:
void Update ()
{
rect1 = new Rect (Screen.width/2,Screen.height/2,25,25);
rect2 = new Rect (rect1.x + rect1.Width, 0, 25,25); //This puts the rect beside the first one always
rect3 = new Rect (rect2.x, rect2.y+rect2.height, 25,25); //This will put rect3 right below rect 2 and still relative to rect 1 as well as rect 2 and so on
}
Answer by maihe-br · Jul 31, 2013 at 10:02 PM
I am having problems like this. I have not finished my problems with Screen.height yet, but you can find what you need to learn in Unity's GUI Scripting Guide, specially in Layout Models section