I have been stuck for a few days, and my searches through google and here haven’t returned what I was looking for. Here is my situation:
When the player hits the “1” key, the hero character will perform an attack. I set a bool to make sure the attack can’t be repeated in the time window. I set a trigger for the animation to occur, and it does, that all works fine. My issue is that I have no idea how to wait for this animation to finish.
I’ve tried (horribly) to use Coroutines, but when I try something to use the animator.GetCurrentAnimatorStateInfo(0).normalized time for a delay, I run into the issue that the animation I want to delay by hasn’t started playing yet, because its on the same frame. I feel like it maybe a problem with how my code is structured.
If anyone could point me in the right direction, I would really appreciate the assistance.
The code:
void Update()
{
HandlePlayerInput();
}
private void HandlePlayerInput()
{
if (isPerformingAction == false)
{
if (Input.GetKeyDown("1"))
{
Attack();
}
}
}
private void Attack()
{
isPerformingAction = true;
PerformAttack();
if (FoesAreDefeated())
{
BattleWon();
}
EndCharacterTurn();
}
private void PerformBasicAction()
{
CurrentHero.animator.SetTrigger("Attack");
**//DELAY HERE USING COROUTINE?**
CalculateDamage();
}
Do you actually want to execute some code once the animation is finished?
– BaldBeardedMonk