実現したいこと
Unity Standard Aseet にある Cameras の Free Look CameraRig を使用しているのですが、
デフォルトではシーン再生時、視点の回転が常にマウスの動きと連動しているのを、
左クリックを押しながらマウスを動かした時のみ、視点が回転するように変更を加えたいのですが、
スクリプトのどの部分を変更すれば良いのかが分からず、変更部分を教えていただきたく思います。
Free Look Camera のスクリプト
using System; using UnityEngine; using UnityStandardAssets.CrossPlatformInput; namespace UnityStandardAssets.Cameras { public class FreeLookCam : PivotBasedCameraRig { [SerializeField] private float m_MoveSpeed = 1f; // How fast the rig will move to keep up with the target's position. [Range(0f, 10f)] [SerializeField] private float m_TurnSpeed = 1.5f; // How fast the rig will rotate from user input. [SerializeField] private float m_TurnSmoothing = 0.0f; // How much smoothing to apply to the turn input, to reduce mouse-turn jerkiness [SerializeField] private float m_TiltMax = 75f; // The maximum value of the x axis rotation of the pivot. [SerializeField] private float m_TiltMin = 45f; // The minimum value of the x axis rotation of the pivot. [SerializeField] private bool m_LockCursor = false; // Whether the cursor should be hidden and locked. [SerializeField] private bool m_VerticalAutoReturn = false; // set wether or not the vertical axis should auto return private float m_LookAngle; private float m_TiltAngle; private const float k_LookDistance = 100f; private Vector3 m_PivotEulers; private Quaternion m_PivotTargetRot; private Quaternion m_TransformTargetRot; protected override void Awake() { base.Awake(); Cursor.lockState = m_LockCursor ? CursorLockMode.Locked : CursorLockMode.None; Cursor.visible = !m_LockCursor; m_PivotEulers = m_Pivot.rotation.eulerAngles; m_PivotTargetRot = m_Pivot.transform.localRotation; m_TransformTargetRot = transform.localRotation; } protected void Update() { HandleRotationMovement(); if ( _LockCursor && Input.GetMouseButtonUp(0)) { Cursor.lockState = m_LockCursor ? CursorLockMode.Locked : CursorLockMode.None; Cursor.visible = !m_LockCursor; } } private void OnDisable() { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } protected override void FollowTarget(float deltaTime) { if (m_Target == null) return; transform.position = Vector3.Lerp(transform.position, m_Target.position, deltaTime*m_MoveSpeed); } private void HandleRotationMovement() { if(Time.timeScale < float.Epsilon) return; var x = CrossPlatformInputManager.GetAxis("Mouse X"); var y = CrossPlatformInputManager.GetAxis("Mouse Y"); m_LookAngle += x*m_TurnSpeed; m_TransformTargetRot = Quaternion.Euler(0f, m_LookAngle, 0f); if (m_VerticalAutoReturn) { m_TiltAngle = y > 0 ? Mathf.Lerp(0, -m_TiltMin, y) : Mathf.Lerp(0, m_TiltMax, -y); } else { m_TiltAngle -= y*m_TurnSpeed; m_TiltAngle = Mathf.Clamp(m_TiltAngle, -m_TiltMin, m_TiltMax); } m_PivotTargetRot = Quaternion.Euler(m_TiltAngle, m_PivotEulers.y , m_PivotEulers.z); if (m_TurnSmoothing > 0) { m_Pivot.localRotation = Quaternion.Slerp(m_Pivot.localRotation, m_PivotTargetRot, m_TurnSmoothing * Time.deltaTime); transform.localRotation = Quaternion.Slerp(transform.localRotation, m_TransformTargetRot, m_TurnSmoothing * Time.deltaTime); } else { m_Pivot.localRotation = m_PivotTargetRot; transform.localRotation = m_TransformTargetRot; } } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/27 00:41