將Cinemachine的freelook改為鼠標右鍵控制轉向


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;
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM