Answer the question
In order to leave comments, you need to log in
Why doesn't the coroutine work?
There is a function to switch the state of the character. I want the switching to happen only after the animation is completed. I made a coroutine, but it doesn't work (Please help.
public void Change_status(Status _status)
{
StartCoroutine(WaitForAnimation("SwordHit"));
status = _status;
if (_status == Status.Attack)
{
if (anim.GetBool(walkAnimName))
{
anim.SetBool(walkAnimName, false);
anim.SetBool("isAttacking", true);
}
}
else if (_status == Status.Walk)
{
if (!anim.GetBool(walkAnimName))
{
anim.SetBool(walkAnimName, true);
anim.SetBool("isAttacking", false);
}
}
else if (_status == Status.Idle)
{
if (!anim.GetBool(walkAnimName))
{
anim.SetBool(walkAnimName, false);
}
}
}
private IEnumerator WaitForAnimation(string _name)
{
while (anim.GetCurrentAnimatorStateInfo(0).IsName(_name))
{
yield return null;
}
}
Answer the question
In order to leave comments, you need to log in
Well, the coroutine does nothing for you. She opened up and everything. And all the code after StartCoroutine will be executed immediately)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question