unity实现摄像机拉近拉远视野

近期做项目时遇到需要实现摄像机视野拉近拉远的效果

用鼠标滚轮实现摄像机视野拉近拉远

代码如下:

private float mouseX;
private float mouseY;
void Update()
{
    if (Input.GetAxis("Mouse ScrollWheel") < 0)
    {
        if (Camera.main.fieldOfView <= 100)
            this.GetComponent().fieldOfView++;
        // 摄像机的正交投影
        if (Camera.main.orthographicSize <= 20)
        this.GetComponent().orthographicSize += 0.5f;
    }
    if (Input.GetAxis("Mouse ScrollWheel") > 0)
    {
        if (this.GetComponent().fieldOfView > 1)
            this.GetComponent().fieldOfView--;
        if (this.GetComponent().orthographicSize >= 1)
            this.GetComponent().orthographicSize -= 0.5f;
    }
}


你可能感兴趣的:(unity,camera)