x


Button and resolution problem

Hello I have a big problem. button change place after a build the project and change the resolution. in unity i work with 1200 * 700 resolution (( 16/9 )) but when a change other resolution or make it iu full screen the button change place. not the same when i put it in unity project. how can i fix that . thanks

more ▼

asked Aug 26 '10 at 12:04 PM

incitement gravatar image

incitement
30 17 17 22

Jeez, I with people would learn how to use the SEARCH field. This question is asked about once a month!

Aug 26 '10 at 01:18 PM Wolfram
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

GUI positions are absolute meaning that they will change their relative position if the screen size changes. To make them relative you need to calculate your Rectangles using factors. eg.:

void OnGUI () {
  public float x, y, width, height;
  Rect pos;
  pos.x = x * Screen.width;
  pos.y = y * Screen.height;
  pos.width = width * Screen.width;
  pos.height = height * Screen.height;

  GUI.Button(pos, "test");
}

With x, y, width and height being values between 0...1 this should lead to relative positioning.

more ▼

answered Aug 26 '10 at 12:35 PM

StephanK gravatar image

StephanK
6k 39 53 93

How can i apply this script. i have many button in my game . should i integrate this script with script of all the button or how. thanks

Aug 26 '10 at 02:48 PM incitement
(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:

x3693
x789
x665
x381
x83

asked: Aug 26 '10 at 12:04 PM

Seen: 2040 times

Last Updated: Aug 26 '10 at 02:21 PM