using UnityEngine; using Cinemachine; using System.Collections; public class CameraController : MonoBehaviour { [SerializeField] private GameObject cam; public float scrollSpeed; public float stopAfterTime = 0.25f; public AnimationCurve curve = new AnimationCurve(new Keyframe(0f, 0f, 1f, 1f), new Keyframe(1f, 1f, 1f, 1f)); [Range(1f, 0f)] public float decelerationMultiplier; public Vector2 sens; private Vector2 defaultMaxSpeed; private float timer; private void Start() { defaultMaxSpeed *= 0; } private void Update() { //defaultMaxSpeed = new Vector2(cam.GetComponent().m_XAxis.m_MaxSpeed, cam.GetComponent().m_YAxis.m_MaxSpeed); if (Input.GetMouseButtonDown(1)) { defaultMaxSpeed = sens; // Enable mouse input cam.GetComponent().m_XAxis.m_InputAxisName = "Mouse X"; cam.GetComponent().m_YAxis.m_InputAxisName = "Mouse Y"; } if (Input.GetMouseButtonUp(1)) { timer = 0; // Disable mouse input cam.GetComponent().m_XAxis.m_InputAxisName = ""; cam.GetComponent().m_YAxis.m_InputAxisName = ""; } cam.GetComponent().m_XAxis.m_MaxSpeed = defaultMaxSpeed.x; cam.GetComponent().m_YAxis.m_MaxSpeed = defaultMaxSpeed.y; float scroll = Input.GetAxis("Mouse ScrollWheel"); cam.GetComponent().m_Offset.z += scroll * scrollSpeed; timer += Time.deltaTime; float evalTime = timer / stopAfterTime; if (!Input.GetMouseButton(1)) defaultMaxSpeed = Vector2.LerpUnclamped(defaultMaxSpeed, Vector2.zero, curve.Evaluate(evalTime)); } }