- Home /
Size and Location of buttons based on screen resolution.
I was wondering how to change the size and placement of a button based on screen resolution. I have been working at this for awhile now and no matter what I do I can't figure it out so I'm looking to you wonderful people for help. What would I change this to?
if (GUI.Button(Rect(30, 795,120,60),skillzButton))
{
pauseCounter = 1;
}
Answer by Joshua · Apr 12, 2011 at 09:27 PM
Use Screen.width and Screen.height to get the current resolution.
Now to have a button always centered, use it like this:
GUI.Button(Rect(Screen.width/2 - x, Screen.height/2 - y, x, y)
I think you get the idea. Using width and height you can make it appear at the same place, always.
The thing about this is, we don't want it cenetered, and when we try to use the -x's and -y's it looks completely different depending on the android device we are using.
Centered was just an example, using this you can make sure its always at for instance 90% width and 10%height. If you then also make it bigger/smaller based on screen size it will always look the same.
Answer by Aleks 1 · Apr 12, 2011 at 09:26 PM
use screen.width (which returns the screens width) and screen. height (which returns the screens height)
hope this helps
Your answer
![](https://koobas.hobune.stream/wayback/20220613122343im_/https://answers.unity.com/themes/thub/images/avi.jpg)