2024-10-17 23:09:51 +03:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Mirror;
|
|
|
|
|
using StateMachine;
|
2024-10-17 17:23:05 +03:00
|
|
|
|
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()
|
|
|
|
|
{
|
2024-10-17 23:09:51 +03:00
|
|
|
|
Debug.Log("ENTER");
|
|
|
|
|
_player.animator.SetBool(AnimJump, true);
|
2024-10-17 17:23:05 +03:00
|
|
|
|
_player.playerRigidbody.AddForce(Vector3.up * _player.jumpForce, ForceMode.Impulse);
|
2024-10-17 23:09:51 +03:00
|
|
|
|
_player.StartCoroutine(ResetJumpAnimation());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerator ResetJumpAnimation()
|
|
|
|
|
{
|
|
|
|
|
yield return new WaitForSeconds(.2f); // Adjust the delay as needed
|
|
|
|
|
_player.animator.SetBool(AnimJump, false);
|
2024-10-17 17:23:05 +03:00
|
|
|
|
}
|
|
|
|
|
|
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-17 23:09:51 +03:00
|
|
|
|
if (_player.isGrounded && (Input.GetAxis("Horizontal") != 0f || Input.GetAxis("Vertical") != 0f) && Input.GetKey(KeyCode.LeftShift))
|
2024-10-17 17:23:05 +03:00
|
|
|
|
{
|
|
|
|
|
_player.StateMachine.SetCurrentState(PlayerState.Run);
|
|
|
|
|
}
|
|
|
|
|
else if (_player.isGrounded)
|
|
|
|
|
{
|
|
|
|
|
_player.StateMachine.SetCurrentState(PlayerState.Walk);
|
|
|
|
|
}
|
2024-10-19 15:28:48 +03:00
|
|
|
|
|
|
|
|
|
_velocity = _player.moveDirection * (_player.runSpeed * .5f) * Time.fixedDeltaTime;
|
|
|
|
|
}
|
2024-10-17 17:23:05 +03:00
|
|
|
|
|
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
|
|
|
|
}
|
2024-10-17 23:09:51 +03:00
|
|
|
|
|
2024-10-17 17:23:05 +03:00
|
|
|
|
public override void Exit()
|
2024-10-17 23:09:51 +03:00
|
|
|
|
{
|
|
|
|
|
// Additional exit logic if needed
|
2024-10-17 17:23:05 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|