- Home /
Resolution question?
Hello. I have a problem with my game's resolution(I think). My current aspect ratio inside the Unity editor is 3:2, my GUI elements are all laid out in their correct positions and they look fine. But, because I used fixed positions rather than screen width/2, screen height/2 + ###, etc. to place the GUI stuff, when I go to another resolution, it is messed up. I was told by someone that I could save myself alot of work and just add this script and Unity would automatically scale my GUI elements correctly. But, I am having some trouble understanding what they meant. Where would I place this bit of code? Would it be in the OnGUI function?
Here is what they said (and here is the original question I asked).
there's another very smooth method to do this and doesn't require you to recalculate the absolute position for every gui element. You can set the transform matrix for gui elements with GUI.matrix. So if you do this:
Vetor3 scale = new Vector3(origWidth /Screen.width, origHeight /
Screen.height, 1); GUI.matrix =Matrix4x4.Scale(scale);
where origWidth and origHeight is the screen size you used when designing the gui you can design you gui in the editor, using a good screen size (e.g. 1920x1200) using absolute positions like you would normally do. Then all you have to do is tell the script the original used screen size and will do the scaling for you. No extra code needed.
Thanks
Your answer
Follow this Question
Related Questions
GUIs Do Not Decrease With Resolution 1 Answer
Make GUI Image one size? 1 Answer
GUI.matrix - invalid matrix 2 Answers
Placing GUI elements? 1 Answer