using System.Collections; using System.Collections.Generic; using UnityEngine; public class MouseLook : MonoBehaviour { public float mouseSensitivity = 200f; public Transform playerBody; public Transform cam; private float xRotation = 0f; private float smoothSpeed = 5f; // how smooth is camera movements // Start is called before the first frame update void Start() { Cursor.lockState = CursorLockMode.Locked; // stops you from click out off the sceen } // Update is called once per frame void Update() { float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime; // mouse imput float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime; // mouse imput xRotation -= mouseY; xRotation = Mathf.Clamp(xRotation, -80f, 73f); // stops you from breaking your neck Quaternion localRotation = Quaternion.Euler(xRotation, 0f, 0f); // left and right movement playerBody.Rotate(Vector3.up * mouseX); // left and right movement cam.Rotate(Vector3.left * mouseY); // up and down movement }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)