Unity - Can not change resolution

做~自己de王妃 提交于 2019-12-12 04:12:53

问题


I am having a problem with my resolution settings for a game I am making for Android. Which ever resolution I place to be rendered it always in resolution 399x639(for portrait) I tried changing in player settings, placing a custom resolution and changing it in code but does not help :( Does anyone have an idea what can be wrong?

Thanx


回答1:


To begin with, you can change the resolution as you said in Edit > Project Settings > Player. I think that you also know how to change it while you're developing (go to the bar above the Game View).

Well, you have to make the game to be independent of the screen resolution. For do that, you can start defining these two variables:

    nativeHeightResolution = 1200.0;
    scaledWidthResolution = nativeHeightResolution / Screen.height * Screen.width

And in the OnGUI() function you can write this:

    GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (Screen.height / nativeHeightResolution, Screen.height / nativeHeightResolution, 1)); 

Then, if you want to draw a label, for example, you could use this:

    function Label_Center(pos : Vector2, text : String, style : GUIStyle) {  //draw a text label from the center of screen + position, with style
       GUI.Label(Rect (pos.x + scaledWidthResolution / 2, pos.y + nativeHeightResolution / 2, 700, 100), text, style);
    }

This is what I have used in my projects. I hope that it have been usefull for you.



来源:https://stackoverflow.com/questions/23118622/unity-can-not-change-resolution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!