GUI Label Size and Position Changes With Resolution

Hey all,

I’m having this very frustrating problem with my HUD GUI interface. I would like to display and textured label in a portion of the screen. The problem is that the position and size get all wonky when I change the screen size/resolution.

Here is my very simple code:

#pragma strict

var missileSymbol : Texture2D;

function OnGUI()
{
var symbolWidth : float = Screen.width / 10;
var symbolHeight : float = Screen.width / 10;

var xPos : float = Screen.width / 2;
var yPos : float = Screen.height / 2;

GUI.Label (Rect(xPos, yPos, symbolWidth, symbolHeight), missileSymbol);
}

How can I fix this problem with code?

Thanks!

You need to have your vars “symbolWidth” “symbolHeight” “xPos” “yPos” in the Update function.

Example:

#pragma strict

var missileSymbol : Texture 2D;

function Update()
{
   var symbolWidth : float = Screen.width / 10;
   var symbolHeight : float = Screen.width / 10;
   var xPos : float = Screen.width / 2;
   var yPos : float = Screen.height / 2;
}

function OnGUI()
{
   GUI.Label (Rect(xPos, yPos, symbolWidth, symbolHeight), missileSymbol);
}

I had the same issue with GUItexts, instead of usign height width and offsets, use the transforms scale and position.

Set the label to 1,1,1 in the scale. Set the width, height and offsets to 0
place the label, click on the game tab at the top. Just to the left of position x or y, when you click two little arrows appear that you can drag to increase and decrease to position.