首先
然后脚本挂在摄像机下
using UnityEngine;
public class CamearAdaptation : MonoBehaviour
{
public float initOrthoSize;
public float initWidth;
public float initHeight;
float factWidth;
float factHeight;
void Start ()
{
factWidth = Screen.width;
factHeight = Screen.height;
//实际正交视口 = 初始正交视口 * 初始宽高比 / 实际宽高比
GetComponent<Camera>().orthographicSize = (initOrthoSize * (initWidth / initHeight)) / (factWidth / factHeight);
}
}