x


scale gui without moving position

Is there a way to scale a gui box,textbox ect.. the same way you scale gui text?

You can scale gui text but unchecking pixel correct and just use the scale boxes under transform and scale it relative to screen size.

example:

alt text When I try to scale a GUI.TextArea,button, box, ect.. it moves were the boxes are located and changes the size of them. I just want the size to change not the location.

example at 1024x768:

alt text

example at 600x 450:

alt text

I would like the gui text area and button to stay in the same general location but scale its length and width like the GUIText does.

Here is the code that I have so far:

 var playerName = "";
var password = "";
//var Nstyle : GUIStyle;
//var Pstyle : GUIStyle;
//var Entstyle: GUIStyle;

//example for resolution independent GUI scaling var native_height : float = 1080; var native_width : float = 1920; var pStyle : GUIStyle;

var actual_height : float; var actual_width : float; var ry : float; var rx : float;

function OnGUI () { //set up scaling actual_height = Screen.height; actual_width = Screen.width; ry = actual_height / native_height; rx = actual_width / native_width;

GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (rx, ry, 1)); playerName = GUI.TextArea (Rect (Screen.width / 2 + 300, Screen.height / 2 + 110, 300, 50), playerName); password = GUI.TextArea (Rect (Screen.width / 2 + 300, Screen.height / 2 + 210, 300, 50), password);

//firstTime = false; if (GUI.Button (Rect (Screen.width / 2 + 300, Screen.height / 2 +280, 130, 40), "Enter")) { PlayerPrefs.SetString("Player Name", playerName); print (PlayerPrefs.GetString("Player Name"));

} }

If anyone can tell me how to fix this that would be great :)

more ▼

asked Jun 27 '10 at 03:33 PM

Ryan 1 gravatar image

Ryan 1
28 1 1 6

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

2 answers: sort voted first

When you do the GUI scaling like you have it there, you don't want to be using Screen.width or Screen.height in your GUI calls for individual GUI elements. Instead you want to use a fixed size. In your example, try doing this:

playerName = GUI.TextArea (Rect (native_width / 2 + 300, native_height / 2 + 110, 300, 50), playerName);
password = GUI.TextArea (Rect (native_width / 2 + 300, native_height / 2 + 210, 300, 50), password);


if (GUI.Button (Rect (native_width / 2 + 300, native_height / 2 +280, 130, 40), "Enter"))     {
// etc
more ▼

answered Jun 27 '10 at 04:29 PM

Tetrad gravatar image

Tetrad
7.2k 27 37 89

thanks that worked :)

Jun 27 '10 at 05:20 PM Ryan 1

Be sure to mark the answer as accepted.

Jun 27 '10 at 05:28 PM Tetrad
(comments are locked)
10|3000 characters needed characters left
playerName = GUI.TextArea (Rect (Screen.width / 2 + 300, Screen.height / 2 + 110, 300, 50), playerName);
    password = GUI.TextArea (Rect (Screen.width / 2 + 300, Screen.height / 2 + 210, 300, 50), password);

Get rid of the +110

Change it to a pure ratio like Screen.height/3

more ▼

answered Jun 27 '10 at 03:40 PM

spinaljack gravatar image

spinaljack
9.1k 18 31 91

(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:

x3695
x388

asked: Jun 27 '10 at 03:33 PM

Seen: 4155 times

Last Updated: Jun 27 '10 at 03:33 PM