Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MouseLook : MonoBehaviour
- {
- public float mouseSensitivity = 100f;
- public Transform playerBody;
- float xRotation = 0f;
- void Start()
- {
- Cursor.lockState = CursorLockMode.Locked;
- }
- // Update is called once per frame
- void Update()
- {
- float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
- float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
- playerBody.Rotate(Vector3.up * mouseX);
- xRotation -= mouseY;
- xRotation = Mathf.Clamp(xRotation, -90f, +90f);
- transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement