Advertisement
leomovskii

MouseLook.cs

Nov 8th, 2021
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MouseLook : MonoBehaviour {
  6.  
  7.     public float mouseSensitivity = 100f;
  8.     public Transform player;
  9.     float xRotation = 0f;
  10.  
  11.     void Start() {
  12.         Cursor.lockState = CursorLockMode.Locked;
  13.     }
  14.  
  15.     void Update() {
  16.         float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
  17.         float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
  18.  
  19.         xRotation -= mouseY;
  20.         xRotation = Mathf.Clamp(xRotation, -90f, 90f);
  21.  
  22.         transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
  23.         player.Rotate(Vector3.up * mouseX);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement