- Home /
Making a button's placement independent of resolution
I am extremely new to Unity.
I have a button which I created using Gui.button(...) function but want to place it slightly to the left of the middle of the screen, independent of screen resolution. So I want the button's right side to be touching the center y-axis of the screen and the button to be resting on the x-axis.
How can I do this?
E.g.
Gui.button(Rect (20,40,80,20), "Level 1"))
is my button, should I set the x position of th button to
x = Screen.Width/2 - (80-20)/2
Thanks.
Answer by robertbu · Mar 25, 2013 at 12:33 AM
GUI coordinates start in the upper left of the screen, and the Rect for displaying the GUI is anchored in the upper left as well. So you are looking for something like:
var x = Screen.Width/2 - button_width;
var y = Screen.Height/2 - button_height;
GUI.Button(Rect(x,y,button_width, button_height), "Level 1");
Where button_width and button_height are the width and height you want to make your button.
Your answer
Follow this Question
Related Questions
GUI Button in the middle of screen? 1 Answer
Android Button Screen 1 Answer
Making a button's placement independent of resolution 0 Answers
Resolutions 1 Answer