Guest User

Untitled

a guest
Oct 5th, 2025
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using TreeEditor;
  2. using UnityEngine;
  3.  
  4. public class MouseMovement : MonoBehaviour
  5. {
  6.  
  7.     public float mouseSens = 480f;
  8.     public Camera viewCamera;
  9.  
  10.     float xRot = 0f;
  11.     float yRot = 0f;
  12.  
  13.     public float maxLookUp = -85;
  14.     public float maxLookDown = 85;
  15.  
  16.     // Start is called once before the first execution of Update after the MonoBehaviour is created
  17.     void Start()
  18.     {
  19.         Cursor.lockState = CursorLockMode.Locked;
  20.     }
  21.  
  22.     // Update is called once per frame
  23.     void Update()
  24.     {
  25.         // register input
  26.         float mouseX = Input.GetAxis("Mouse X") * mouseSens * Time.deltaTime;
  27.         float mouseY = Input.GetAxis("Mouse Y") * mouseSens * Time.deltaTime;
  28.  
  29.         // vertical look, clamped cos your ass aint that flexible
  30.         xRot -= mouseY;
  31.         xRot = Mathf.Clamp(xRot, maxLookUp, maxLookDown);
  32.  
  33.         // horizontal look so you can hit them clips
  34.         yRot += mouseX;
  35.         transform.localRotation = Quaternion.Euler(0f, yRot, 0f);
  36.         viewCamera.transform.localRotation = Quaternion.Euler(xRot, 0f, 0f);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment