Unity3D 鼠标滚轮
场景:Unity3D鼠标滚轮统制摄像机远近
Unity3D鼠标滚轮控制摄像机远近
Unity3D鼠标滚轮控制摄像机远近
// 鼠标中间键 var MouseWheelSensitivity = 5; var MouseZoomMin = 2; var MouseZoomMax = 10;
摄像机距离视角中心最近为2,最远为10,鼠标灵敏度为5
// 如果按住滑轮 if (Input.GetAxis("Mouse ScrollWheel") != 0) { //Debug.Log(Input.GetAxis("Mouse ScrollWheel")); //Debug.Log(distance); if (normalDistance >= MouseZoomMin && normalDistance <= MouseZoomMax) { normalDistance -= Input.GetAxis("Mouse ScrollWheel") * MouseWheelSensitivity; } if (normalDistance < MouseZoomMin) { normalDistance = MouseZoomMin; } if (normalDistance > MouseZoomMax) { normalDistance = MouseZoomMax; } }