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

public class MouseLook : MonoBehaviour
{


    public float mouseSensitivity = 100.0f;
    float xRotation = 0.0f;
    float pitch, yaw;

    public Transform playerTransform;


    private void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;

        pitch = 0.0f;
        yaw = 0.0f; 
    }


    // https://www.youtube.com/watch?v=_QajrabyTJc
    void Update()
    {
        Vector2 mouseInput = mouseSensitivity * new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));

        //Debug.Log("mouseInput: " + mouseInput);

        xRotation -= mouseInput.y;
        xRotation = Mathf.Clamp(xRotation, -90.0f, 90.0f);
        yaw += mouseInput.x;
        pitch = xRotation;
        

        transform.localRotation = Quaternion.Euler(xRotation, 0.0f, 0.0f);
        playerTransform.rotation = Quaternion.Euler(0.0f, yaw, 0.0f);  
        
    }
}
