![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/bc7fc7d1106e3d20b247ff6eb24b7298.png)
public class AdjustMatchMode : MonoBehaviour
{
public float standard_width = 1920f;
public float standard_height = 1080f;
float device_width = 0f;
float device_height = 0f;
float adjustor = 0f;
void Start()
{
device_width = Screen.width;
device_height = Screen.height;
float standard_aspect = standard_width / standard_height;
float device_aspect = device_width / device_height;
if (device_aspect < standard_aspect)
{
adjustor = standard_aspect / device_aspect;
}
CanvasScaler canvasScalerTemp = transform.GetComponent<CanvasScaler>();
if (adjustor == 0)
{
canvasScalerTemp.matchWidthOrHeight = 1;
}
else
{
canvasScalerTemp.matchWidthOrHeight = 0;
}
}
}