[SOLVED]Positioning a GuiTexture

Hi,

I’m having a hard time, tryng to understand how to get this working correctly.
I have a texture, of size 697x188, and i want to place this texture on the bottom right corner.
Although i got this working, once i change resolution, the gui texture also changes position.
I have it setup like this :

Pixel Inset
x = 0
y = 0
width = 697
height = 188

The borders all at zero
Position at zero

And in a script, on the Start function, i do the following :

transform.position.y = -0.007;
transform.position.x = 0.48;

How can i make this work ? Is there some example somewhere, on how to make the gui screen resolution independent ?

thanks,
Bruno

If you are going to want your GUI to adjust itself according to the screen resolution, then you need to apply a matrix to it:

There are quite a few threads in the forum with some useful info about that, like this one with an example:

http://forum.unity3d.com/viewtopic.php?t=26090

Thanks for the link.
However, i already spotted this, and i still can’t get this to work, the Matrix is simply ignored.

I have it this way, on the OnGui function :

GUI.matrix = Matrix4x4.TRS(transform.position,Quaternion.identity,Vector3((Screen.width / nativeHeight,(Screen.height / nativeHeight), 1.0));

Replacing transform.position does nothing either.

But my problem is the gui positioning, not the gui scaling, and as i see this is just for scaling.

Use of GUI matrices is for UnityGUI, not GUIText/GUITextures. As to your problem, you can try setting the transform.position values or manipulate the pixel inset values only (put object at 0,0,0). In either case you might need to monitor the screen size and at run-time make the necessary adjustments to keep the various elements where you want them.

This is the way I do it.

Very simple and straightforward, and works with all resolutions. I use something like the code below, then adjust the adjustx and the adjusty to move the texture (which is referenced through the GUIstyle) wherever i want on screen (even the bottoom corner) (and then I stop the game and re-enter the numbers the asjustx and the adjusty in the inspector and re-save the scene) and it stays there for all resolutions, even in the bottom corner.

The texture in this case is 105 by 105 pixels and stretch in the GUIstyle is off.

var adjustx21 : float;
var TTF_GUI : GUIStyle;
//********************
GUILayout.BeginArea(Rect(Screen.width*adjustx21-105,Screen.height*adjusty21-105,Screen.width,Screen.height));
  GUILayout.BeginHorizontal();
     GUILayout.Button ("",texture_GUI)
  GUILayout.EndHorizontal();
GUILayout.EndArea();

I make everything resolution-independent: ditch all the pixel inset stuff, and make the x scale (for example) .2 and the y scale .1. Then, to always be in the lower-right, the x position would be .9 and the y position would be .05. Done. :slight_smile: Works with all resolutions, uses no scripting.

–Eric

wheres the fun in that ?

to Eric5h5
yes, it works for standalone app. But I have troubles in the window mode in web player - my logo got out the window. But when I run fullscreen mode - it works fine

198837--7304--$snap2_188.jpg

Did you change all the pixel inset values to 0, and use the normal position and scale values only? I have no issues with any size window or screen when doing that, including the web player.

–Eric

Some screenshots

  • full screen mode (1920x1200) in web player
  • settings
  • full screen mode (1920x1200) in standalone
    P.S
    and I noticed that logo is out of the screen also in the stand alone app when I decrease resolution

198952--7317--$snap3browserfullscreen_199.jpg
198952--7318--$standalonefullscreen_170.jpg
198952--7319--$settings_100.jpg

Haa!! I have found working parameters.
X axis position should be 1 (for bottom right corner) but X of Pixel inset shoud be the same as image Width but with opposite sign.

So now everithing is Ok with all resolutions and all players. 8)

198985--7323--$goodparrameters_100.jpg

@HiggyB - I understand that the way "manual"you said would be done as follows, if I want the application has 1024x768 I’ll have to manually make the positioning of GUI and so on, but when it is full screen as I proceed?

Thanks,
FDF

well, with scripting, you can do this, just use Screen.width - texture.width - 10 ect (this is in the OnGUI function, but I assume you can do this in any function, just change it a little)