aboutsummaryrefslogtreecommitdiff
path: root/Assets/Scripts/CameraFOVBinding.cs
blob: 1275fe87386398f7c1eaccab695c65d604310cb4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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);
    }
}