x


Making GUI elements in the same relative place in any resolution

How do I make it so that my GUI textures stay in the top right/left no matter the pixel size. And in the middle on the top. because my problem is my screen on one of my computers is huge compared to the tiny resolution on my laptop. So when I play my game on the laptop you can see the health bar or instructions cause they are to high. So how do you make it so that your GUI textures are allays able to be seen. I need them to be on the top right.. and the top middle. Thanks in advance.

more ▼

asked Nov 09 '10 at 05:56 PM

RingOfStorms gravatar image

RingOfStorms
4 5 6 8

Please use titles and tags that make some sort of sense and are useful.

Nov 09 '10 at 08:20 PM Eric5h5

Guys what he is asking is how to use a matrix4x4.

Aug 25 '12 at 03:39 PM landon91235
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

From http://unity3d.com/support/documentation/Components/gui-Basics.html

You can use the Screen.width and Screen.height properties to get the total dimensions of the screen space available in the player.

/* Screen.width & Screen.height example */

function OnGUI () {
GUI.Box (Rect (0,0,100,50), "Top-left");
GUI.Box (Rect (Screen.width - 100,0,100,50), "Top-right");
GUI.Box (Rect (0,Screen.height - 50,100,50), "Bottom-left");
GUI.Box (Rect (Screen.width - 100,Screen.height - 50,100,50), "Bottom-right");

}

more ▼

answered Nov 09 '10 at 08:02 PM

Ben 18 gravatar image

Ben 18
25 2 2 7

(comments are locked)
10|3000 characters needed characters left

Yea this is just like in teh forums and this is NOT WHAT I AM ASKING for. I do not care about the Fucntion o nGUI crap. I'm looking for a way to change the GUI_Texture (NOT MAKE THEM) theis means I have my own picture that I need to move. I do not want to make another rectabgle. I do not care about that in this case. So I need a solution for a GUI_Texture... not GUI

more ▼

answered Nov 09 '10 at 09:15 PM

RingOfStorms gravatar image

RingOfStorms
4 5 6 8

(comments are locked)
10|3000 characters needed characters left

If you create a GUITexture there will be a public variable in the inspector called texture. You can add your own 2D texture here. You can change the position in the transform component X and Y settings. (0, 0) is bottom-left, (1,1) is top right.

You could also follow Ben's advice, change Box for Label and add something like the code bellow in the script. This way you'll get full control of the style settings.

From Reference Manusal Scripting Guide

/* Overriding the default Control Style with one you've defined yourself */

var customLabel : GUIStyle;

function OnGUI () {
    // Make a button. We pass in the GUIStyle defined above as the style to use
    GUI.Label (Rect (10,10,150,20), "I am a Custom Label", customLabel);
}
more ▼

answered Nov 09 '10 at 10:32 PM

LeiterJakab gravatar image

LeiterJakab
87 3 3 12

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3673
x378

asked: Nov 09 '10 at 05:56 PM

Seen: 2345 times

Last Updated: Aug 25 '12 at 03:39 PM