38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using StateMachine;
|
|
using UnityEngine;
|
|
|
|
namespace Player.States
|
|
{
|
|
public class Run : State<PlayerState>
|
|
{
|
|
private readonly Player _player;
|
|
private static readonly int AnimRun = Animator.StringToHash("Run");
|
|
|
|
public Run(Player player) : base(PlayerState.Run)
|
|
{
|
|
_player = player;
|
|
}
|
|
|
|
public override void Enter()
|
|
{
|
|
_player.animator.SetBool(AnimRun, true);
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
Vector3 velocity = _player.moveDirection * (_player.runSpeed * Time.deltaTime);
|
|
|
|
_player.playerRigidbody.velocity = new Vector3(velocity.x, _player.playerRigidbody.velocity.y, velocity.z);
|
|
|
|
if (Input.GetKeyUp(KeyCode.LeftShift) || (Input.GetAxis("Horizontal") == 0f && Input.GetAxis("Vertical") == 0f))
|
|
{
|
|
_player.StateMachine.SetCurrentState(PlayerState.Walk);
|
|
}
|
|
}
|
|
|
|
public override void Exit()
|
|
{
|
|
_player.animator.SetBool(AnimRun, false);
|
|
}
|
|
}
|
|
} |