using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraController : MonoBehaviour
{
    [SerializeField] private float _mouseSensitivityX = 2f;
    [SerializeField] private float _mouseSensitivityY = 2f;

    [SerializeField] private float _minVerticalAngle = -75f;
    [SerializeField] private float _maxVerticalAngle = 45f;

    [SerializeField] private Transform _controller;

    private float _xRotation = 0f;
    private float _yRotation = 0f;

    void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * _mouseSensitivityX;
        float mouseY = Input.GetAxis("Mouse Y") * _mouseSensitivityY;

        _yRotation += mouseX;
        _xRotation -= mouseY;

        _xRotation = Mathf.Clamp(_xRotation, _minVerticalAngle, _maxVerticalAngle);

        transform.localRotation = Quaternion.Euler(_xRotation, 0f, 0f);

        if (_controller != null)
        {
            _controller.rotation = Quaternion.Euler(0f, _yRotation, 0f);
        }
    }
}
