GUI and Screenresolution scale Problem

HI,

I used the FPS Tutorial to create a game.
Now i got some serious problems with the GUI.
I designed some Icons for health, rocket ammo and mg ammo and used this for a texture in GUITexture objects.
The problem is, if i change the screen resolution the health bars (and the other too) stay at the same position. So if you use a smaller resolution the GUI dissapears.
I solved the problem for the large boxes with the onGUI function (example below)

var healthGUI : Texture;
function OnGUI () {
		GUI.DrawTexture(Rect(0,Screen.height - 128, 256, 128), healthGUI);

}

, but the small bars who show ammo and health couldn’t be placed this way because they get scaled inside the FPS script. The textgui’s have the same problem.

So, this is what i want:
How can i place the bars on a position where they move up/down/left/right when i change the screen resolution?
or
How can I configure the build options that there is only 1 resolution avaiable if you want to play the game. (Then I could arrange the bars with fixed values.)

As an Attachment theres the FPS script, which I modified.
And a Screenshot to show you how my GUI looks.
The small bars and text GUIs are not on their correct position at the moment, obviously.
I think you can imagine where they should be. :wink:

278501–9981–$fpsplayer_957.js (3.98 KB)

One solution is to use GUI.matrix

Here’s some example (JS) code:

// this sets our "virtual" screen for the GUI.matrix stuff
private var tMatrix;
private var width=1680;
private var height=1050; 


function OnGUI() {
	tMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3(1.0*Screen.width/width, 1.0*Screen.height/height, 1.0));
	GUI.matrix = tMatrix;

// rest of your GUI stuff

}

This makes your GUI scaled to a 1680x1050 (16:10) resolution, and scales if you resize it, even while running. If you don’t want to support resize-while-running, you can save performance by doing the matrix calculation (the "tMatrix = … " line) in Start().

If you use this, DO use hardcoded pixel offsets instead of referring to screen height or width.