summaryrefslogtreecommitdiff
path: root/Assets/Scripts/GrabStateMachine.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/GrabStateMachine.cs')
-rw-r--r--Assets/Scripts/GrabStateMachine.cs25
1 files changed, 2 insertions, 23 deletions
diff --git a/Assets/Scripts/GrabStateMachine.cs b/Assets/Scripts/GrabStateMachine.cs
index 8242097..4695457 100644
--- a/Assets/Scripts/GrabStateMachine.cs
+++ b/Assets/Scripts/GrabStateMachine.cs
@@ -2,16 +2,9 @@ using UnityEngine;
public class GrabStateMachine : MonoBehaviour
{
- private bool grabbing = false;
-
- // 动画组件引用(需要在Inspector面板赋值,或通过代码自动获取)
- [Header("动画组件引用")]
+ public PlayerControl playerControl;
[SerializeField] private Animator anim;
- // 按键设置(可在Inspector面板修改,无需硬编码)
- [Header("控制按键")]
- [SerializeField] private KeyCode grabKey = KeyCode.G;
-
/// <summary>
/// 初始化
/// </summary>
@@ -22,26 +15,12 @@ public class GrabStateMachine : MonoBehaviour
private void Update()
{
- DetectGrabKeyInput();
UpdateAnimatorState();
}
- private void DetectGrabKeyInput()
- {
- if (Input.GetKey(grabKey))
- {
- grabbing = true;
- }
-
- if (Input.GetKeyUp(grabKey))
- {
- grabbing = false;
- }
- }
-
private void UpdateAnimatorState()
{
- anim.SetBool("grabbing", grabbing);
+ anim.SetBool("grabbing", playerControl.grabbing);
}
}