using System; using UnityEngine; public class CameraFOVWithDistance : MonoBehaviour { public PlayerTracker tracker; public Camera camera; public RectTransform uiScale; public float lerpSpeed = 0.15f; private float _targetFOV; private float _minDistance = 6.4f; private float _maxDistance = 14.4f; private float _minFOV = 35f; private float _maxFOV = 73f; private void Update() { var percent = Mathf.InverseLerp(_minDistance, _maxDistance, Math.Clamp(tracker.Distance, _minDistance, _maxDistance)); uiScale.localScale = Vector3.one * Mathf.Lerp(1.0f, 1.1f, percent); _targetFOV = Mathf.Lerp(_minFOV, _maxFOV, percent); } private void FixedUpdate() { camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, _targetFOV, lerpSpeed); } }