Why my animator is freezzed after WaitForSeconds(Delay)
I have a character with Movement and Attack script. I set animations with bool parameters.
After i Get damage animator is set TakeDamage animation buy won't play until WaitForSeconds(Delay), Why?
This is my code public void TakeDamage(int damage) { healthScript.GetDamage(damage);
StartCoroutine(SetTakeDamage());
//getDamageSound.Play();
ifGotDamage = true;
if (healthScript.health == 0)
{
Die();
}
}
IEnumerator SetTakeDamage()
{
anim.SetBool(AnimationTags.TAKE_DAMAGE_PARAMETER, true);
yield return new WaitForSeconds(takeDamageFrequency);
anim.SetBool(AnimationTags.TAKE_DAMAGE_PARAMETER, false);
}
So i solved the problem by changing bool parameter to trigger. After that animations from AnyState are working propely.
But another problem came. Because trigger doesn't have "False" condition i can't transition to idle entry state
Answer by privatecontractor · Jan 19 at 03:15 PM
Hi @remanam,
more or less: " yield return new WaitForSeconds(takeDamageFrequency);" will stop Animator for takeDamageFrequency seconds.... so you can try code below, maybe it will help.
IEnumerator SetTakeDamage()
{
float _remainingTimeToAnimDamage = takeDamageFrequency;
while (_remainingTimeToAnimDamage > 0)
{
anim.SetBool(AnimationTags.TAKE_DAMAGE_PARAMETER,
true);
_remainingTimeToAnimDamage -= Time.deltaTime;
yield return null;
}
anim.SetBool(AnimationTags.TAKE_DAMAGE_PARAMETER,
false);
yield return null;
}
Actually it didn't help, animator was frezzed until takeDamageFrequency