Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class MouseMovement : MonoBehaviour
- {
- public float mouseSensitivity = 100f;
- public float minVerticalRotation = -90f;
- public float maxVerticalRotation = 90f;
- private float verticalRotation = 0f;
- private PlayerMovement playerMovement;
- private Transform currentCamera;
- void Start()
- {
- Cursor.lockState = CursorLockMode.Locked;
- playerMovement = GetComponent<PlayerMovement>();
- UpdateCameraReference();
- }
- void Update()
- {
- UpdateCameraReference();
- HandleMouseMovement();
- }
- void UpdateCameraReference()
- {
- currentCamera = playerMovement.isMale ? playerMovement.maleCamera : playerMovement.femaleCamera;
- }
- void HandleMouseMovement()
- {
- float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
- float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
- verticalRotation -= mouseY;
- verticalRotation = Mathf.Clamp(verticalRotation, minVerticalRotation, maxVerticalRotation);
- currentCamera.localRotation = Quaternion.Euler(verticalRotation, 0f, 0f);
- transform.Rotate(Vector3.up * mouseX);
- }
- public float GetVerticalRotation()
- {
- return verticalRotation;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement