2024-10-17 17:23:05 +03:00
|
|
|
|
using StateMachine;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Player.States
|
|
|
|
|
{
|
|
|
|
|
public class Walk : State<PlayerState>
|
|
|
|
|
{
|
|
|
|
|
private readonly Player _player;
|
|
|
|
|
private static readonly int AnimWalk = Animator.StringToHash("Walk");
|
|
|
|
|
|
|
|
|
|
public Walk(Player player) : base(PlayerState.Walk)
|
|
|
|
|
{
|
|
|
|
|
_player = player;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Enter()
|
|
|
|
|
{
|
|
|
|
|
_player.animator.SetBool(AnimWalk, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update()
|
|
|
|
|
{
|
|
|
|
|
Vector3 velocity = _player.moveDirection * (_player.walkSpeed * Time.deltaTime);
|
|
|
|
|
|
|
|
|
|
_player.playerRigidbody.velocity = new Vector3(velocity.x, _player.playerRigidbody.velocity.y, velocity.z);
|
|
|
|
|
|
2024-10-17 23:09:51 +03:00
|
|
|
|
if (Input.GetKey(KeyCode.LeftShift) && (Input.GetAxis("Horizontal") != 0f || Input.GetAxis("Vertical") != 0f))
|
2024-10-17 17:23:05 +03:00
|
|
|
|
{
|
|
|
|
|
_player.StateMachine.SetCurrentState(PlayerState.Run);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Exit()
|
|
|
|
|
{
|
|
|
|
|
_player.animator.SetBool(AnimWalk, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|