Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MouseMovement : MonoBehaviour
- {
- public float mouseSensitivity = 100f;
- float xRotation = 0f;
- float YRotation = 0f;
- void Start()
- {
- //Locking the cursor to the middle of the screen and making it invisible
- Cursor.lockState = CursorLockMode.Locked;
- }
- void Update()
- {
- float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
- float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
- //control rotation around x axis (Look up and down)
- xRotation -= mouseY;
- //we clamp the rotation so we cant Over-rotate (like in real life)
- xRotation = Mathf.Clamp(xRotation, -90f, 90f);
- //control rotation around y axis (Look up and down)
- YRotation += mouseX;
- //applying both rotations
- transform.localRotation = Quaternion.Euler(xRotation, YRotation, 0f);
- }
- }
Advertisement
Comments
-
- what have i do wrong, if i wanna add the script to my player pop there a window up:
- Can't add script
- Can't add script component 'movement' because the script dass cannot be found. Make Sure that there are no compilor errors and that the file name and class name match.
- can anyone help me?
Add Comment
Please, Sign In to add comment
Advertisement