File size: 1,093 Bytes
3497d64 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseMovement : MonoBehaviour
{
public float mouseSensitivity = 100f;
float xRotation = 0f;
float YRotation = 0f;
void Start()
{
//Locking the cursor to the middle of the screen and making it invisible
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
if (!InventorySystem.Instance.isOpen && !CraftingSystem.Instance.isOpen)
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
// Debug.Log("Mouse X: " + mouseX);
//control rotation around x axis (Look up and down)
xRotation -= mouseY;
//we clamp the rotation so we cant Over-rotate (like in real life)
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
//control rotation around y axis (Look up and down)
YRotation += mouseX;
//applying both rotations
transform.localRotation = Quaternion.Euler(xRotation, YRotation, 0f);
}
}
} |