diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-06-03 07:37:22 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2026-06-03 07:37:22 +0800 |
| commit | f86c25987c023fcc80c21c6f40da1e79af96ab45 (patch) | |
| tree | 3f29f99638c7531b12b7b0c4411331f6bf92e2b7 /Assets/Scripts | |
| parent | 65c80579d0791026ae1a2fd5327f3e520973c09b (diff) | |
增加冲刺时的相机视角变化
Diffstat (limited to 'Assets/Scripts')
| -rw-r--r-- | Assets/Scripts/CameraFOVBinding.cs | 25 | ||||
| -rw-r--r-- | Assets/Scripts/CameraFOVBinding.cs.meta | 11 |
2 files changed, 36 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); + } +} diff --git a/Assets/Scripts/CameraFOVBinding.cs.meta b/Assets/Scripts/CameraFOVBinding.cs.meta new file mode 100644 index 0000000..3de5aa7 --- /dev/null +++ b/Assets/Scripts/CameraFOVBinding.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 01e207a32ce88164f9563034ae06f0d8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |
