using UnityEngine;

public class CameraLook : MonoBehaviour
{
    public float sensitivity = 100f;
    public Transform playerBody;

    float xRotation = 0f;

    void Update()
    {
        float mouseX = 0f;
        float mouseY = 0f;

        if (Input.GetKey(KeyCode.LeftArrow)) mouseX = -1f;
        if (Input.GetKey(KeyCode.RightArrow)) mouseX = 1f;

        if (Input.GetKey(KeyCode.UpArrow)) mouseY = 1f;
        if (Input.GetKey(KeyCode.DownArrow)) mouseY = -1f;

        mouseX *= sensitivity * Time.deltaTime;
        mouseY *= sensitivity * Time.deltaTime;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -80f, 80f);

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

        playerBody.Rotate(Vector3.up * mouseX);
    }
}