今天给大家介绍的是FirstPersonController下的FOVKick 脚本,可能有些人对FOVKick是干什么的都不知道,为此,就详细的说明下该脚本:
-
-
-
-
- [Serializable]
- public class FOVKick
- {
- public Camera Camera;
- [HideInInspector] public float originalFov;
- public float FOVIncrease = 3f;
- public float TimeToIncrease = 1f;
- public float TimeToDecrease = 1f;
- public AnimationCurve IncreaseCurve;
-
-
- public void Setup(Camera camera)
- {
- CheckStatus(camera);
-
-
- Camera = camera;
- originalFov = camera.fieldOfView;
- }
-
-
- private void CheckStatus(Camera camera)
- {
- if (camera == null)
- {
- throw new Exception("FOVKick camera is null, please supply the camera to the constructor");
- }
-
- if (IncreaseCurve == null)
- {
- throw new Exception(
- "FOVKick Increase curve is null, please define the curve for the field of view kicks");
- }
- }
-
-
- public void ChangeCamera(Camera camera)
- {
- Camera = camera;
- }
-
-
- public IEnumerator FOVKickUp()
- {
-
- float t = Mathf.Abs((Camera.fieldOfView - originalFov)/FOVIncrease);
- while (t < TimeToIncrease)
- {
-
- Camera.fieldOfView = originalFov (IncreaseCurve.Evaluate(t/TimeToIncrease)*FOVIncrease);
- t = Time.deltaTime;
-
- yield return new WaitForEndOfFrame();
- }
- }
-
-
- public IEnumerator FOVKickDown()
- {
-
- float t = Mathf.Abs((Camera.fieldOfView - originalFov)/FOVIncrease);
-
- while (t > 0)
- {
-
- Camera.fieldOfView = originalFov (IncreaseCurve.Evaluate(t/TimeToDecrease)*FOVIncrease);
- t -= Time.deltaTime;
- yield return new WaitForEndOfFrame();
- }
-
-
- Camera.fieldOfView = originalFov;
- }
- }
这个玩意就是极品飞车中使用氮氧装置加速后,视野增大往后倾的一种感觉,很棒!嗯,回去打开游戏来试试,是有这种感觉吧?印象有点不深了。
哦,是Minecraft,话说unity的FPC脚本效果跟Minecraft中的好像。