using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 鼠标滚轮控制相机视野的变化 /// public class MouseMiddleControlCamera : MonoBehaviour { [Header("相机视角的最小值")] [Range(0,100)] public float m_CameraFieldOfViewMin; [Header("相机视角的最大值")] [Range(0, 100)] public float m_CameraFieldOfViewMax; private void Awake() { m_CameraFieldOfViewMin = 15; m_CameraFieldOfViewMax = 100; } // Use this for initialization void Start () { } // Update is called once per frame void Update () { //鼠标滚轮的效果 //camera.main.fieldofview摄像机的视野 //Camera.main.orthographicSize摄像机的正交投影 //Zoom out 缩小 //GetAxis获得轴,Mouse ScrollWheel鼠标滚轮 if (Input.GetAxis("Mouse ScrollWheel") < 0) { if (Camera.main.fieldOfView <= m_CameraFieldOfViewMax) Camera.main.fieldOfView += 2; if (Camera.main.orthographicSize <= 10) Camera.main.orthographicSize += 1f; } //Zoom in 放大 if (Input.GetAxis("Mouse ScrollWheel") > 0) { if (Camera.main.fieldOfView > m_CameraFieldOfViewMin) Camera.main.fieldOfView -= 2; if (Camera.main.orthographicSize >= 1) Camera.main.orthographicSize -= 1f; } } }