问题
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