将该代码附加到camera上,devHeight和devWidth修改为设计分辨率
using UnityEngine;
public class GameCamera : MonoBehaviour
{
float devHeight = 1920f;
float devWidth = 1080f;
void Start()
{
float orthographicSize = this.GetComponent<Camera>().orthographicSize;
orthographicSize = orthographicSize / (devHeight / devWidth) * (Screen.height * 1.0f / Screen.width);
this.GetComponent<Camera>().orthographicSize = orthographicSize;
}
}
摄像机尺寸Size除以设计时的高宽比,再乘以实际屏幕高宽比,得到同宽度时应设置的Size