- Home /
Mobile OnGUI
Hi, there. I recently started to develop games for mobile platforms but I have some GUI size problem according to different screen sizes. This is a pretty common topic, but I could not figure out a suitable solution. I am using: GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (horizRatio, vertRatio, 1));
When I implemented all my textures, labels .I used set float rather than Screen.height. However, my problem is that the texture will stretch/compress to fit the screen and have a different shape. I thought the function will keep the original shape but just scale up, but it doesn't. Here I have a few questions: 1, Did I have a wrong native resolution so that it does match different screens? 2. What is the best way to fit all 16:9(android), 4:3(ipad), and 3:2 (iphone) ?
Thank you very much. Any direct or suggestions provide I'd greatly appreciated.
Answer by Mehrdad995 · Jul 29, 2013 at 12:04 PM
Hi I couldn't understand very well if you mean you want to save the original shape of your GUI do this:
var myGuiTexture : GUITexture
function OnGUI(){
myGuiTexture.pixelInset.width = 0.05*Screen.width;
myGuiTexture.pixelInset.height = 0.05*Screen.width;
// this will keep the size of your GUI 0.05 of the screen size which depend on screen width
//so you can change the 0.05 to anything
//in order to save the original shape you want
}
Hope this helped :)
Thanks for the help. But I solved my problem with this : scaleFactor = (float)Screen.width / (float) referenceResolutionWidth; Then just multiple this to every textures.