using StateMachine; using UnityEngine; namespace Player.States { public class Walk : State { 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); } private Vector3 _velocity; public override void Update() { _velocity = _player.moveDirection * _player.walkSpeed * Time.fixedDeltaTime; if (Input.GetKey(KeyCode.LeftShift) && (Input.GetAxis("Horizontal") != 0f || Input.GetAxis("Vertical") != 0f)) { _player.StateMachine.SetCurrentState(PlayerState.Run); } } public override void FixedUpdate() { _player.playerRigidbody.velocity = new Vector3(_velocity.x, _player.playerRigidbody.velocity.y, _velocity.z); } public override void Exit() { _player.animator.SetBool(AnimWalk, false); } } }