- Home /
Mecanim Triggers Not Deactivating
Ok, so I'm animating a character that can slide. At the end of the slide I call SetTrigger("SlideFinished") once to come out of the slide. My issue is that the trigger works the first time, but then stays activated, rather than deactivating as soon as it transitions.
Here is the code I am using, this is the only way the SetTrigger() is called, and it doesn't get called more than once per slide:
IEnumerator SlideEnd()
{
float endTime = Time.time + k_SlideTime;
while(true)
{
if(m_RunnerAnimator != null)
{
if(endTime < Time.time || m_IsWalled || CheckCollision(m_GroundCheck.transform.position, 0.5f ) == true)
{
m_RunnerAnimator.SetBool(k_Anim_Grounded, false);
m_RunnerAnimator.SetTrigger (k_Anim_SlideFinished);
break;
}
}
yield return null;
}
Any help would be much appreciated!
Comment
Solved the issue. The animation was getting interrupted by another animation on the same frame. I just waited for the next fixed update before setting grounded to false:
IEnumerator SlideEnd()
{
float endTime = Time.time + k_SlideTime;
while(true)
{
if(m_RunnerAnimator != null)
{
if(endTime < Time.time || m_IsWalled || CheckCollision(m_GroundCheck.transform.position, 0.5f ) == true)
{
m_RunnerAnimator.SetTrigger (k_Anim_SlideFinished);
yeild return new WaitForFixedUpdate();
m_RunnerAnimator.SetBool(k_Anim_Grounded, false);
break;
}
}
yield return null;
}