42 lines
1.2 KiB
C#
Raw Normal View History

2024-10-17 17:23:05 +03:00
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);
}
2024-10-19 15:28:48 +03:00
private Vector3 _velocity;
2024-10-17 17:23:05 +03:00
public override void Update()
{
2024-10-19 15:28:48 +03:00
_velocity = _player.moveDirection * _player.runSpeed * Time.fixedDeltaTime;
2024-10-17 17:23:05 +03:00
2024-10-17 23:09:51 +03:00
if (Input.GetKeyUp(KeyCode.LeftShift) || (Input.GetAxis("Horizontal") == 0f && Input.GetAxis("Vertical") == 0f))
2024-10-17 17:23:05 +03:00
{
_player.StateMachine.SetCurrentState(PlayerState.Walk);
}
}
2024-10-19 15:28:48 +03:00
public override void FixedUpdate()
{
_player.playerRigidbody.velocity = new Vector3(_velocity.x, _player.playerRigidbody.velocity.y, _velocity.z) ;
}
2024-10-17 17:23:05 +03:00
public override void Exit()
{
_player.animator.SetBool(AnimRun, false);
}
}
}