Files
BABA_YAGA/Assets/Scripts/Player Controller/PlayerParkourState.cs

55 lines
1.9 KiB
C#

using UnityEngine;
namespace OnlyScove.Scripts
{
public class PlayerParkourState : PlayerBaseState
{
private readonly int parkourHash = Animator.StringToHash("Step Up");
private float animationDuration;
private float timer;
public PlayerParkourState(PlayerStateMachine stateMachine) : base(stateMachine) {}
public override void Enter()
{
Debug.Log("<color=orange>[PlayerParkourState]</color> Entered Parkour State");
if (stateMachine.Anim != null && stateMachine.Anim.layerCount > 0)
{
// Play the Parkour animation (Step Up)
// Use the overload with layer index 0 to be explicit
stateMachine.Anim.CrossFadeInFixedTime(parkourHash, 0.1f, 0);
}
timer = 0f;
}
public override void Tick(float deltaTime)
{
timer += deltaTime;
// Simple way to wait for animation: check normalized time of the current state
var stateInfo = stateMachine.Anim.GetCurrentAnimatorStateInfo(0);
if (stateInfo.shortNameHash == parkourHash && stateInfo.normalizedTime >= 1f)
{
if (stateMachine.Input.MoveInput == Vector2.zero)
stateMachine.SwitchState(new PlayerIdleState(stateMachine));
else
stateMachine.SwitchState(new PlayerMoveState(stateMachine));
}
// Safety timeout if animation doesn't play or something
if (timer > 2f)
{
stateMachine.SwitchState(new PlayerIdleState(stateMachine));
}
}
public override void PhysicsTick(float fixedDeltaTime)
{
// Usually during parkour we disable gravity or handle it specially
stateMachine.VelocityY = 0;
}
public override void Exit() {}
}
}