evelynshilosky

MouseMovement - Part 31

Feb 1st, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MouseMovement : MonoBehaviour
  6. {
  7.  
  8.     public float mouseSensitivity = 100f;
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.     float xRotation = 0f;
  16.     float YRotation = 0f;
  17.  
  18.     void Start()
  19.     {
  20.  
  21.  
  22.         //Locking the cursor to the middle of the screen and making it invisible
  23.         Cursor.lockState = CursorLockMode.Locked;
  24.  
  25.  
  26.     }
  27.  
  28.  
  29.     void Update()
  30.     {
  31.  
  32.         if (!InventorySystem.Instance.isOpen && !CraftingSystem.Instance.isOpen && !MenuManager.Instance.isMenuOpen && !DialogueSystem.Instance.dialogueUIActive && !QuestManager.Instance.isQuestMenuOpen)
  33.         { //To Lock MouseMovement a screen is open
  34.             float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
  35.             float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
  36.  
  37.             //control rotation around x axis (Look up and down)
  38.             xRotation -= mouseY;
  39.  
  40.             //we clamp the rotation so we cant Over-rotate (like in real life)
  41.             xRotation = Mathf.Clamp(xRotation, -90f, 90f);
  42.  
  43.             //control rotation around y axis (Look up and down)
  44.             YRotation += mouseX;
  45.  
  46.  
  47.             //applying both rotations
  48.             transform.localRotation = Quaternion.Euler(xRotation, YRotation, 0f);
  49.         }
  50.  
  51.     }
  52. }
  53.  
Add Comment
Please, Sign In to add comment