首先,您可以按照编辑 > 项目设置 > 播放器中的说明更改分辨率。我认为您也知道如何在开发时更改它(转到游戏视图上方的栏)。
好吧,你必须让游戏独立于屏幕分辨率。为此,您可以开始定义这两个变量:
nativeHeightResolution = 1200.0;
scaledWidthResolution = nativeHeightResolution / Screen.height * Screen.width
在 OnGUI() 函数中你可以这样写:
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (Screen.height / nativeHeightResolution, Screen.height / nativeHeightResolution, 1));
然后,如果你想绘制一个标签,例如,你可以使用这个:
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);
}
这是我在项目中使用的。希望对你有用。