- Home /
GUI Buttons scaling with resolution - help
Hello everyone,
I have another problem.
I'm trying to make the GUI Buttons and Volume Slider I have created scale with the resolution so that it stays in the same place on the screen no matter what resolution you have.
I have pretty much zero experience in js and it's taken me a couple of hours to even get this far:
function OnGUI () { if (GUI.Button (Rect (370, 240, 180, 30), "Low")) { }
if (GUI.Button (Rect (555, 240, 180, 30), "Medium")) {
}
if (GUI.Button (Rect (740, 240, 180, 30), "High")) {
}
}
This simply displays the GUI buttons, how do I make them scale?
Thanks
Answer by Dreamer · May 11, 2011 at 10:00 AM
What you need is a GUI that is independent from resolution. Put below line at every of your OnGUI function. And set your own standard resolution values.
var standardResolutionX:float= 1024; var standardResolutionY:float= 768;
function OnGUI () { GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3(Screen.width / standardResolutionX, Screen.height /standardResolutionY, 1));
if (GUI.Button (Rect (370, 240, 180, 30), "Low")) {
}
if (GUI.Button (Rect (555, 240, 180, 30), "Medium")) {
}
if (GUI.Button (Rect (740, 240, 180, 30), "High")) {
}
}
Answer by Sam 9 · May 12, 2011 at 09:43 AM
This works, however it only seems to scale correctly on the X axis (screenwidth). The buttons are still not scaling on Y
Your answer
Follow this Question
Related Questions
How to make button stay the same size on all screens? 2 Answers
Button and resolution problem 1 Answer
Changing screen resolution with GUI Buttons 0 Answers
full screen and resolution 1 Answer