#How do I stop a new animation starting until the current one finished using code on animator?

1 messages · Page 1 of 1 (latest)

oblique bay
deep perch
silent girder
#

If these are setup in an Animator, and you're triggering the Animations with variable transitions, you could modify the settings below "Has Exit Time" in the animation transition

oblique bay
oblique bay
silent girder
#

Exit Time (and the settings below it in the animation transition menu) tell the animation how it's allowed to move from a state to another.
How are you animations set up?

oblique bay
oblique bay
deep perch
# oblique bay How would I go about comparing the time? I don't understand what role it played ...

If your controlling the animations by code, you could do something similar to this for example:

void SomeFunc()
{
anim.Play("Some State");
//or
anim.SetTrigger("SomeTrigger");
}

void Update()
{
var state = GetCurrentAnimatorStateInfo(0);
if (state.normalizedTime > state.length) {SomeOtherFunc();}//"some state" has been playing longer than its length, which means its done and another state can safely be transitioned to
}

If you are instead controlling this entirely through the Animator window, then I dont think this API would help in your case though - I could be wrong, you may need a second animation variable for your transition back, if you dont want the transition to be instant after the first state finishes

Having "Has Exit Time" OFF means that if you play another animation it will transition instantly - if that bool is ON, then by default I think its 0.8 or 0.9 (meaning 80% or 90%) of the animation MUST finish playing before the next state will transition (unless you play the animation by name, then it overrides this setting entirely and plays instantly), though I could be misremembering some of that information