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

40 lines
1012 B
C#

using UnityEngine;
using Cinemachine;
public class CameraController : MonoBehaviour
{
[SerializeField] private GameObject cam;
public float scrollSpeed;
public Vector2 sens;
private Vector2 defaultMaxSpeed;
private void Start()
{
defaultMaxSpeed *= 0;
}
private void Update()
{
defaultMaxSpeed = new Vector2(cam.GetComponent<CinemachineFreeLook>().m_XAxis.m_MaxSpeed, cam.GetComponent<CinemachineFreeLook>().m_YAxis.m_MaxSpeed);
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;
}
}