1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- /// <summary>
- /// 鼠标滚轮控制相机视野的变化
- /// </summary>
- 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;
- }
- }
- }
|