3DTD/Assets/Scripts/Camera/CameraController.cs

40 lines
1012 B
C#
Raw Normal View History

using UnityEngine;
using Cinemachine;
public class CameraController : MonoBehaviour
{
2024-04-20 16:52:39 +02:00
[SerializeField] private GameObject cam;
2024-04-20 16:52:39 +02:00
public float scrollSpeed;
2024-04-20 16:52:39 +02:00
public Vector2 sens;
private Vector2 defaultMaxSpeed;
2024-04-20 16:52:39 +02:00
private void Start()
{
defaultMaxSpeed *= 0;
}
2024-04-20 16:52:39 +02:00
private void Update()
{
defaultMaxSpeed = new Vector2(cam.GetComponent<CinemachineFreeLook>().m_XAxis.m_MaxSpeed, cam.GetComponent<CinemachineFreeLook>().m_YAxis.m_MaxSpeed);
2024-04-20 16:52:39 +02:00
if (Input.GetMouseButtonDown(1))
{
defaultMaxSpeed = sens;
}
if (Input.GetMouseButtonUp(1))
{
defaultMaxSpeed *= 0;
}
cam.GetComponent<CinemachineFreeLook>().m_XAxis.m_MaxSpeed = defaultMaxSpeed.x;
cam.GetComponent<CinemachineFreeLook>().m_YAxis.m_MaxSpeed = defaultMaxSpeed.y;
float scroll = Input.GetAxis("Mouse ScrollWheel");
cam.GetComponent<CinemachineCameraOffset>().m_Offset.z += scroll * scrollSpeed;
}
}