2024-01-24 00:48:26 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
|
|
namespace BlueWaterProject
|
|
|
|
{
|
2024-01-28 15:46:56 +00:00
|
|
|
public class DashBehavior : StateMachineBehaviour
|
2024-01-24 00:48:26 +00:00
|
|
|
{
|
2024-01-26 16:26:50 +00:00
|
|
|
private CombatPlayerController combatPlayerController;
|
2024-01-24 00:48:26 +00:00
|
|
|
|
|
|
|
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
|
|
|
{
|
2024-01-26 16:26:50 +00:00
|
|
|
if (combatPlayerController == null)
|
2024-01-24 00:48:26 +00:00
|
|
|
{
|
2024-01-26 16:26:50 +00:00
|
|
|
combatPlayerController = animator.GetComponentInParent<CombatPlayerController>();
|
2024-01-24 00:48:26 +00:00
|
|
|
}
|
2024-01-26 16:26:50 +00:00
|
|
|
var animationLength = stateInfo.length;
|
|
|
|
animator.speed = animationLength / combatPlayerController.GetDashTime();
|
|
|
|
|
2024-01-28 15:46:56 +00:00
|
|
|
combatPlayerController.SetIsInvincibility(true);
|
2024-01-26 16:26:50 +00:00
|
|
|
combatPlayerController.SetIsDashing(true);
|
|
|
|
combatPlayerController.SetEnableDashing(false);
|
2024-01-24 00:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
|
|
|
{
|
|
|
|
if (stateInfo.normalizedTime >= 1.0f)
|
|
|
|
{
|
2024-01-26 16:26:50 +00:00
|
|
|
animator.SetBool(PhysicsMovement.IsDashingHash, false);
|
2024-01-24 00:48:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
|
|
|
{
|
2024-01-26 16:26:50 +00:00
|
|
|
animator.speed = 1f;
|
|
|
|
combatPlayerController.SetIsDashing(false);
|
2024-01-28 15:46:56 +00:00
|
|
|
combatPlayerController.SetIsInvincibility(false);
|
2024-01-24 00:48:26 +00:00
|
|
|
|
2024-01-26 16:26:50 +00:00
|
|
|
combatPlayerController.CoolDown(combatPlayerController.GetDashCooldown(), () => combatPlayerController.SetEnableDashing(true));
|
2024-01-24 00:48:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|