Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class mouseControl : MonoBehaviour
- {
- public float sensitivity = 10f;
- public float maxYAngle = 45f;
- public Vector2 currentRotation;
- Transform player;
- private void Start()
- {
- player = GetComponent<Transform>;
- currentRotation = new Vector2(player.rotation.y*180, player.rotation.x*180);
- }
- void Update()
- {
- currentRotation.x += Input.GetAxis("Mouse X") * sensitivity
- currentRotation.y -= Input.GetAxis("Mouse Y") * sensitivity;
- currentRotation.x = Mathf.Repeat(currentRotation.x, 360);
- currentRotation.y = Mathf.Clamp(currentRotation.y, -maxYAngle, maxYAngle);
- player.rotation = Quaternion.Euler(currentRotation.y, currentRotation.x, 0);
- if (Input.GetMouseButtonDown(0)
- {
- Cursor.lockState = CursorLockMode.Locked;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment