| | using System.Collections; |
---|
| | using System.Collections.Generic; |
---|
| | using UnityEngine; |
---|
| | |
---|
| | public class CameraBehaviour : MonoBehaviour |
---|
| | { |
---|
| | [ SerializeField ] private Transform followTarget; |
---|
| | |
---|
| | [ SerializeField ] private float rotationSpeed = 10f ; |
---|
| | [ SerializeField ] private float bottomClamp = -40f ; |
---|
| | [ SerializeField ] private float topClamp = 70f ; |
---|
| | |
---|
| | private float cinemachineTargetPitch; |
---|
| | private float cinemachineTargetYaw; |
---|
| | |
---|
| | |
---|
| | |
---|
| | { |
---|
| | |
---|
| | } |
---|
| | |
---|
| | |
---|
| | |
---|
| | { |
---|
| | CameraRotation(); |
---|
| | } |
---|
| | |
---|
| | private float GetMouseInput ( ) => Input.GetAxis(axis) * rotationSpeed * Time.deltaTime; |
---|
| | |
---|
| | private void CameraRotation () |
---|
| | { |
---|
| | float mouseX = GetMouseInput("Mouse X" ); |
---|
| | float mouseY = GetMouseInput("Mouse Y" ); |
---|
| | |
---|
| | cinemachineTargetPitch = UpdateRotation(cinemachineTargetPitch, mouseY, bottomClamp, topClamp, true ); |
---|
| | cinemachineTargetYaw = UpdateRotation(cinemachineTargetYaw, mouseX, float .MinValue, float .MaxValue, false ); |
---|
| | |
---|
| | ApplyRotations(cinemachineTargetPitch, cinemachineTargetYaw); |
---|
| | } |
---|
| | |
---|
| | private void ApplyRotations ( ) => followTarget.rotation = Quaternion.Euler(pitch, yaw, followTarget.eulerAngles.x); |
---|
| | |
---|
| | private float UpdateRotation ( float currentRotation, float input, float min, float max, bool isXAxis ) |
---|
| | { |
---|
| | currentRotation += isXAxis ? -input : input; |
---|
| | return Mathf.Clamp(currentRotation, min, max); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |