- Home /
Animation plays only once
Hey, i have created an animation and want to call it with a state based machine. In the machine i have set a trigger named "Charge" to call the clip. But the clip only plays once (despite the fact that the SetTrigger("Charge") function is called every .5 seconds in the code).
My code (the parts that are relevant):
void Update () { timer += Time.deltaTime;
if (type == style.Circle)
{
if (timer >= delay)
{
//play charging animation
if (charge)
{
anim.SetTrigger("Charge");
}
else
shootCircle();
timer = 0f;
}
}
}
The type enum is set to style.Circle and the charge bool is set to true. If i set charge to false the shootCircle() methode is called properly so the trigger is defenetly called. delay is set to .5 seconds.
Here are a few screenshots that might come handy:
alt textalt textalt text The transition:
alt text
And the Charge Animation:
alt text
Thank you so much for your help! And sorry for my bad english.
Answer by DiegoSLTS · Jun 08, 2015 at 02:03 PM
You're never returning from the Charge state, you have to go back to Empty after the Charge animation finishes. Add a transition from Charge to Empty with "Has Exit Time" checked and it should work.
Oh i see. Can i see "Has Exit Time" as trigger that is triggered if the animation is over?
btw thanks man! It's working now!
Great! Glad it worked. "Has exit time" indicates that the "exit time" of the transition should be used. If you expand the "Settings" option you'll see an "Exit time" field. That exit time is the duration of the state, it can be any value, if it's less than the duration of the animation it'll transition back before finishing. You can combine exit time with other conditions. Look here for more details: http://docs.unity3d.com/$$anonymous$$anual/class-Transition.html
$$anonymous$$aybe you can think of it like a trigger, yes.