diff options
Diffstat (limited to 'Assets/Scripts/CameraFOVBinding.cs')
| -rw-r--r-- | Assets/Scripts/CameraFOVBinding.cs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Assets/Scripts/CameraFOVBinding.cs b/Assets/Scripts/CameraFOVBinding.cs new file mode 100644 index 0000000..1275fe8 --- /dev/null +++ b/Assets/Scripts/CameraFOVBinding.cs @@ -0,0 +1,25 @@ +using System; +using DS; +using UnityEngine; + +[RequireComponent(typeof(CameraHandler))] +public class CameraFOVBinding : MonoBehaviour +{ + public Camera camera; + public float normalFOV; + public float runningFOV; + private CameraHandler _cameraHandler; + private PlayerLocomotion _playerLocomotion; + + private void Start() + { + _cameraHandler = GetComponent<CameraHandler>(); + _playerLocomotion = _cameraHandler.player.gameObject.GetComponent<PlayerLocomotion>(); + } + + private void FixedUpdate() + { + var targetFOV = _playerLocomotion.isSprinting ? runningFOV : normalFOV; + camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, targetFOV, 0.12f); + } +} |
