LegitTeddyBears

Error Practice Key

Apr 26th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class mouseControl : MonoBehaviour
  6. {
  7.  
  8.     public float sensitivity = 10f;
  9.     public float maxYAngle = 45f;
  10.     public Vector2 currentRotation;
  11.     Transform player;
  12.  
  13.     private void Start()
  14.     {
  15.         player = GetComponent<Transform>();
  16.        
  17.         currentRotation = new Vector2(player.rotation.y*180, player.rotation.x*180);
  18.     }
  19.  
  20.     void Update()
  21.     {
  22.         currentRotation.x += Input.GetAxis("Mouse X") * sensitivity;
  23.  
  24.         currentRotation.y -= Input.GetAxis("Mouse Y") * sensitivity;
  25.  
  26.         currentRotation.x = Mathf.Repeat(currentRotation.x, 360);
  27.  
  28.         currentRotation.y = Mathf.Clamp(currentRotation.y, -maxYAngle, maxYAngle);
  29.  
  30.         player.rotation = Quaternion.Euler(currentRotation.y, currentRotation.x, 0);
  31.  
  32.         if (Input.GetMouseButtonDown(0))
  33.         {
  34.             Cursor.lockState = CursorLockMode.Locked;
  35.         }
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment