Advertisement
Guest User

Untitled

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