https://forum.unity.com/threads/how-do-i-make-a-cinemachinefreelook-orbiting-camera-that-only-orbits-when-the-mouse-key-is-down.527634/#post-3468444
用CM給的案例來測試,直接把下邊的代碼掛到CM攝像機上,代碼來自上邊的鏈接
https://forum.unity.com/threads/whats-the-best-strategy-for-mouse-drag-to-rotate-camera-with-cinemachine-free-look-camera.815355/
(這個鏈接有手機端的代碼,目前我還沒涉及到,先馬着)
using System.Collections; using System.Collections.Generic; using UnityEngine; using Cinemachine; public class CMFreelookOnlyWhenRightMouseDown : MonoBehaviour { void Start(){ CinemachineCore.GetInputAxis = GetAxisCustom; } public float GetAxisCustom(string axisName){ if(axisName == "Mouse X"){ if (Input.GetMouseButton(1)){ return UnityEngine.Input.GetAxis("Mouse X"); } else{ return 0; } } else if (axisName == "Mouse Y"){ if (Input.GetMouseButton(1)){ return UnityEngine.Input.GetAxis("Mouse Y"); } else{ return 0; } } return 0; } }