- Home /
Problem with GUI on different resolutions
Hi everybody, i'm making a game for ios devices and i have a problem with the gui size on different devices.
I use the next script for make it responsive to any screen:
private float originalWidth = 768.0f;
private float originalHeight = 1024.0f;
scale.x = Screen.width / originalWidth;
scale.y = Screen.height / originalHeight;
scale.z = 1;
Matrix4x4 svMat = GUI.matrix;
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
... GUI ELEMENTS HERE ...
GUI.matrix = svMat;
Works fine for devices with the same proportional ratio, for example this script works well with ipad devices(4:3), but when i change to iphone 5s (71:40) the elements of gui are stretched.
Is there any solution to this problem?
Regards,
I don't know if this helps, but maybe this tutorial might answer your question.
Answer by Kermit · Mar 18, 2014 at 01:37 PM
I found a solution for the problem!
Scale only the vertical and assign to horizontal:
float yScale = Screen.height/640f;
GUI.matrix = Matrix4x4.TRS(Vector3.zero,Quaternion.identity,new Vector3(yScale, yScale, 1f));
Now works like a charm!
Regards,
Your answer
Follow this Question
Related Questions
How do I make the size of GUI objects the same across all resolutions? 3 Answers
Button as a child of a button 0 Answers
Using Unity for a IOS Menu Only 0 Answers
How to pick up object on touch? 1 Answer
size of GUI pics too big 1 Answer