Hy sorry for this but i really need help cause i am a bad programmer.
I need a script to keep the GUI resolution at the same resolution like the player. Pleeeeeesssssss
![]()
Hi, welcome to the forum!
There are two basic ways to accomplish this. The most straightforward is to define all your coordinates, widths and heights in terms of Screen.width and Screen.height. So, for example, if you want a rectangle that is set in by a tenth of the width/height, a quarter of the screen wide and an eighth tall, you would use:-
var buttonRect = new Rect(Screen.width * 0.1, Screen.height * 0.1, Screen.width * 0.25, Screen.width * 0.125);
Of course, this involves a lot of extra typing if you have many controls.
The other way is to change the value of GUI.matrix to reflect the different screen sizes. Basically, you design the GUI for a certain resolution (say 800x600) and then set the matrix as follows:-
var designWidth = 800.0;
var designHeight = 600.0;
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3(Screen.width / designWidth, Screen.height / designHeight, 1));
You should be able to drop this code in at the top of your OnGUI function and set the designWidth and designHeight values as appropriate.
I cannot thank you enough for this. I was on the verge of doing your solution A on every control of my game (thats a lot of control, like 1000). I was planning 2-3 days doing this making sure the custom code from a lot of my interface would be correct (I hardcoded a lot of values to do custom stuff, so not just a simple conversion).
I decided to do a quick search on the forum for a solution. Iām happy I did. Took me 10 seconds instead of some days and Iām not talking about potential errors I could have made while converting.
Thanks so much again !
Mick