Mapping GUI Locations?

For my GUI Label it appears in the top right location ( 10 , 10 ) and, I understand I can change it and mess with it to find the correct location but, it feels like im handling it wrong. So i wanted to know if there was a ‘technique’ for mapping the GUI locations without trial and error?

GUI, in most cases, have to take into consideration the width and height of the screen, so if you for instance want to place something in the bottom right corner with 10 px margin:

private var screenResolution : Vector2;

function Start () {
    screenResolution = Vector2(Screen.width, Screen.height); //Store the resolution in a Vector2
}

function OnGUI () {
    GUI.Label (Rect (screenResolution.x-110, screenResolution.y-30, 100, 20), "Hello World!"); //Take width and height into consideration and place the label 10 pixels to the bottom right regardless of resolution
}

All GUI positioning uses [Rect][1] which is a struct. Its structural order is x, y, width and height.

So if you want to place objects alongside each other, take their width and/or height into consideration and place the next object right after, for instance having two equal boxes alongside each other with 10 pixels margin:

GUI.Label (Rect (Screen.width-110, Screen.height-30, 100, 20), "Box 2");
GUI.Label (Rect (Screen.width-220, Screen.height-30, 100, 20), "Box 1");

I made you a simple script where you can test out these conditions easier and understand the logic. Attach it to the camera and set the variables in the Inspector. ‘Use Screen’ will reverse the positioning from top-left to bottom-right.

#pragma strict

var labelRects : Rect[] = new Rect[2]; //X, Y, Width and Height
var labelContents : GUIContent[] = new GUIContent[2]; //The content can either be a string or a texture
var useScreen : boolean[] = new boolean[2]; //Inverts the top-left to bottom-right positioning

function OnGUI () {
	for (var i : int = 0; i < labelRects.Length; i++) {
		if (useScreen*) {*

GUI.Label(Rect(-labelRects.x+Screen.width-labelRects.width, -labelRects.y+Screen.height-labelRects.height, labelRects.width, labelRects_.height), labelContents*);
} else {
GUI.Label(labelRects, labelContents);
}
}
}
[1]: http://unity3d.com/support/documentation/ScriptReference/Rect.html*_