43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
namespace BaseGames.Player.States
|
|
{
|
|
/// <summary>跑步状态。播放 Run 动画并驱动水平移动。</summary>
|
|
public class RunState : PlayerStateBase
|
|
{
|
|
public RunState(PlayerController owner) : base(owner) { }
|
|
|
|
public override void OnStateEnter()
|
|
{
|
|
if (AnimCfg?.Run != null)
|
|
Anim.Play(AnimCfg.Run);
|
|
}
|
|
|
|
public override void OnStateUpdate()
|
|
{
|
|
if (!Move.IsGrounded)
|
|
{
|
|
_owner.TransitionTo(_owner.FallState);
|
|
return;
|
|
}
|
|
if (Buffer.ConsumeJump())
|
|
{
|
|
_owner.TransitionTo(_owner.JumpState);
|
|
return;
|
|
}
|
|
if (Mathf.Abs(Input.MoveInput.x) < 0.1f)
|
|
{
|
|
_owner.TransitionTo(_owner.IdleState);
|
|
return;
|
|
}
|
|
|
|
Move.Move(Input.MoveInput.x * (Cfg != null ? Cfg.RunSpeed : 7f));
|
|
}
|
|
|
|
public override void OnStateFixedUpdate()
|
|
{
|
|
Move.Move(Input.MoveInput.x * (Cfg != null ? Cfg.RunSpeed : 7f));
|
|
}
|
|
}
|
|
}
|