42 lines
1.3 KiB
C#
Raw Normal View History

2024-10-17 17:23:05 +03:00
using StateMachine;
using UnityEngine;
namespace Player.States
{
public class Jump : State<PlayerState>
{
private readonly Player _player;
private static readonly int AnimJump = Animator.StringToHash("Jump");
public Jump(Player player) : base(PlayerState.Jump)
{
_player = player;
}
public override void Enter()
{
_player.animator.SetTrigger(AnimJump);
_player.playerRigidbody.AddForce(Vector3.up * _player.jumpForce, ForceMode.Impulse);
}
public override void Update()
{
if (_player.isGrounded && (Input.GetAxis("Horizontal") != 0f || Input.GetAxis("Vertical") != 0f))
{
_player.StateMachine.SetCurrentState(PlayerState.Run);
}
else if (_player.isGrounded)
{
_player.StateMachine.SetCurrentState(PlayerState.Walk);
}
Vector3 velocity = _player.moveDirection * (_player.runSpeed * .5f * Time.deltaTime);
_player.playerRigidbody.velocity = new Vector3(velocity.x, _player.playerRigidbody.velocity.y, velocity.z);
}
public override void Exit()
{
// _player.animator.SetTrigger(AnimJump); prizemlilsa
}
}
}