JavaScript -> Unity GUI resolution help

Hey, i’m quite new to Unity GUI so any help will be appreciated.

I have GUI textures for my health bar for example. And this is the code i’ve got.
if (curHp > 0)
{
GUI.DrawTexture(Rect(5, 5, hpBarLength, 20), HpBarTexture);

}

This works fine for me and no matter what i change the resolution to, it stays the same.

But i also have GUI Text to show the amount of health for example, but this i can’t seem to get it like the Rect like above.

To get the GUIText i created it from the “GameObject”, “Create Other”, i mean, i ave it working fine it reacts with my scripts for example. But then when the resolution changes it doesn’t stay in the same place.

I’m sure this is to do with the fact that in the “inspector” i can only seem to manipulate the positions with the “Pixel Offset” which means it obviously changes on resolution due to the pixel changes. How would i go about making it so it’s like the GUI.DrawTexture and is the same for all resolutions.

I hope this makes sense.

Would i have to try attaching scripts to the GUITexts in the Hierarchy, or would coding the texts instead of using the GUITexts work better?

I’m not too sure ^^

Also on this note, it would look a lot better if i could have a GUI box behind the health bars for example, is there a specific way to layer this or different ways to do it?

Thanks all.

If you look in the editor, there is a position element at the top. It goes from 0 to 1 and stays the same for all resolutions.

So change the x,y,z position from 0 to 1?

If the x is 0, it will be on the left side of the screen. If it is one, it will be on the right side of the screen. Same with y, but up and down. Z isn’t used.

well this is not working for me. 0,0 is the center of the screen. -0.5 seems to be the left and 0.5 is the right. but then this still doesn’t stay the same when the resolution is changed

The easiest way to make text appear on GUI is with a label.

GUI.Label(Rect(x, y, width, height), textStringVariable);

You can make a box like this:

GUI.Box(Rect(x, y, width, height), "");