diff options
| author | SmallFox <2806143047@qq.com> | 2026-05-14 21:17:29 +0800 |
|---|---|---|
| committer | SmallFox <2806143047@qq.com> | 2026-05-14 21:17:29 +0800 |
| commit | 41def44651b5a7c9e917395fad5e7b480640a3a2 (patch) | |
| tree | fe99b653b956a1be62392ddb2a5eae31f34e09a9 /Assets/Scripts/AnimatorHandler.cs | |
| parent | 738e4b973666742b077c285272d9eb50072d49dd (diff) | |
Movement完工
写完了移动,准备开工相机视角
Diffstat (limited to 'Assets/Scripts/AnimatorHandler.cs')
| -rw-r--r-- | Assets/Scripts/AnimatorHandler.cs | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/Assets/Scripts/AnimatorHandler.cs b/Assets/Scripts/AnimatorHandler.cs new file mode 100644 index 0000000..d95d12b --- /dev/null +++ b/Assets/Scripts/AnimatorHandler.cs @@ -0,0 +1,92 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace DS +{ + public class AnimatorHandler : MonoBehaviour + { + public Animator animator; + private int _vertical; + private int _horizontal; + public bool canRotate; + + public void Initialize() + { + animator = GetComponent<Animator>(); + _vertical = Animator.StringToHash("Vertical"); + _horizontal = Animator.StringToHash("Horizontal"); + } + + public void UpdateAnimatorValues(float verticalMovement, float horizontalMovement) + { + #region Vertical + + float v = 0; + + if (verticalMovement > 0 && verticalMovement < 0.55f) + { + v = 0.5f; + } + else if(verticalMovement > 0.55f) + { + v = 1; + } + else if (verticalMovement < 0 && verticalMovement > -0.55f) + { + v = -0.5f; + } + else if(verticalMovement < -0.55f) + { + v = -1; + } + else + { + v = 0; + } + + #endregion + + #region Horizontal + + float h = 0; + + if (horizontalMovement > 0 && horizontalMovement < 0.55f) + { + h = 0.5f; + } + else if(horizontalMovement > 0.55f) + { + h = 1; + } + else if (horizontalMovement < 0 && horizontalMovement > -0.55f) + { + h = -0.5f; + } + else if(horizontalMovement < -0.55f) + { + h = -1; + } + else + { + h = 0; + } + + #endregion + + animator.SetFloat(_vertical,v,0.1f,Time.deltaTime); + animator.SetFloat(_horizontal,h,0.1f,Time.deltaTime); + } + + public void CanRotate() + { + canRotate = true; + } + + public void StopRotation() + { + canRotate = false; + } + } + +} |
