我希望相机对屏幕做出响应,所以我写了下面的代码。问题是,当我打开应用程序时,商为零。没有错误,并且所有变量都已设置。
using UnityEngine;
public class CamSet : MonoBehaviour
{
public float camWidth;
public float camHeigh;
public Camera camera;
public float quotient;
void Update()
{
quotient = Screen.height / Screen.width;
Debug.Log("height/width = " + quotient);
camWidth = quotient * camHeigh;
camera.rect = new Rect(.05f, .05f, camWidth, camHeigh);
}
}
预先感谢您的帮助。