Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void LateUpdate()
- {
- if (GameSettings.menuOpened)
- return;
- if (currentSensitivityX != GameSettings.mouseSensitivityX || currentSensitivityY != GameSettings.mouseSensitivityY)
- {
- currentSensitivityX = GameSettings.mouseSensitivityX;
- currentSensitivityY = GameSettings.mouseSensitivityY;
- }
- sensitivityX = currentSensitivityX * (GameSettings.currentFOV / GameSettings.defaultFOV);
- sensitivityY = currentSensitivityY * (GameSettings.currentFOV / GameSettings.defaultFOV);
- if (axes == RotationAxes.MouseX)
- {
- #if UNITY_EDITO
- rotationX += Input.GetAxis("Mouse X") * sensitivityX;
- #else
- rotationX += GameSettings.lookDirection.x * sensitivityX;
- #endif
- rotationX = ClampAngle(rotationX, minimumX, maximumX);
- Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
- transform.localRotation = originalRotation * xQuaternion;
- }
- if (axes == RotationAxes.MouseY)
- {
- #if UNITY_EDITO
- rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
- #else
- rotationY += GameSettings.lookDirection.y * sensitivityY;
- #endif
- rotationY = ClampAngle(rotationY, minimumY, maximumY);
- Quaternion yQuaternion = Quaternion.AngleAxis(-rotationY, Vector3.right);
- transform.localRotation = originalRotation * yQuaternion;
- }
- if (axes == RotationAxes.MouseOrbit && reachedTarget && target)
- {
- #if UNITY_EDITO
- rotationX += Input.GetAxis("Mouse X") * sensitivityX;
- rotationY -= Input.GetAxis("Mouse Y") * sensitivityY;
- #else
- rotationX += GameSettings.lookDirection.x * sensitivityX;
- rotationY += GameSettings.lookDirection.y * sensitivityY;
- #endif
- rotationX = ClampAngle(rotationX, minimumX, maximumX);
- rotationY = ClampAngle(rotationY, minimumY, maximumY);
- Quaternion rotation = Quaternion.Euler(rotationY, rotationX, 0);
- Vector3 position = rotation * new Vector3(0.0f, 0.0f, -distance) + target.position;
- transform.rotation = rotation;
- transform.position = position;
- }
- }
- public static float ClampAngle(float angle, float min, float max)
- {
- if (angle < -360F)
- {
- angle += 360F;
- }
- if (angle > 360F)
- {
- angle -= 360F;
- }
- return Mathf.Clamp(angle, min, max);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement