blob: 2d564c3faa3cd7120af8b923f5091a59f5aabc72 (
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
26
27
28
29
30
31
|
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);
}
}
|