此代码使用Screen.width和Screen.height ..它在我的PC上可以正常工作,但是当我将其导出到Android时,它无法正常工作..我花了很多时间研究此代码..非常感谢如果有人可以帮助..
我尝试过Screen.Width
和Screen.Height
。
void Awake()
{
float screenRatio = (float)Screen.width / (float)Screen.height;
float targetRatio = rink.bounds.size.x / rink.bounds.size.y;
if (gameObject.name == "GameCamera")
{
CheckResolution();
}
}
private void CheckResolution()
{
// For Resolution 1080 XX 2340
if ((float)Screen.width == 1080f && (float)Screen.height == 2340f)
{
Vector3 newPos = new Vector3(0f, -90f, 0f);
UiElements.transform.position += newPos;
Vector3 pausePos = new Vector3(0f, 40f, 0f);
pauseUI.transform.position += pausePos;
}
else if ((float)Screen.width == 1080f && (float)Screen.height == 2160f)
{
Vector3 newPos = new Vector3(0f, -40f, 0f);
UiElements.transform.position += newPos;
Vector3 pausePos = new Vector3(0f, 20f, 0f);
pauseUI.transform.position += pausePos;
}
else if ((float)Screen.width == 720f && (float)Screen.height == 1440f)
{
Vector3 newPos = new Vector3(0f, -50f, 0f);
UiElements.transform.position += newPos;
Vector3 pausePos = new Vector3(0f, 20f, 0f);
pauseUI.transform.position += pausePos;
}
else
{
Vector3 newPos = new Vector3(0f, 0f, 0f);
UiElements.transform.position += newPos;
Vector3 pausePos = new Vector3(0f, 0f, 0f);
pauseUI.transform.position += pausePos;
}
}
我要检查Android设备是否具有特定分辨率。并据此调整游戏对象的位置。