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

public class CamMouseLook : MonoBehaviour {

    private float rotY = 0.0f;
    private float rotX = 0.0f;

    public float minX = -60f;
    public float maxX = 60f;

    public bool canLookUpAndDown = true;

    public float mouseSensitivity = 200.0f;

    void Start()
    {
        rotY = transform.localRotation.eulerAngles.y;
        rotX = transform.localRotation.eulerAngles.x;

        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
    }

    private void Update()
    {
        float mouseX = Input.GetAxis("Mouse X");
        rotY += mouseX * mouseSensitivity * Time.deltaTime;

        if (canLookUpAndDown == true)
        {
        float mouseY = Input.GetAxis("Mouse Y") * -1;
        rotX += mouseY * mouseSensitivity * Time.deltaTime;
        rotX = Mathf.Clamp(rotX, minX, maxX);
        }

        Quaternion newRotation = Quaternion.Euler(rotX, rotY, 0.0f);
        transform.rotation = newRotation;
    }
}