Hi There,
I am trying to write a simple function that allows the current animation (which would be looping) to play up to it’s last frame, then play a list of other animations, the last one being a looping one again.
A sequence that would resemble this:-
- LoopingAnimation
- TransitionalAnimation
- TransitionalAnimation
- TransitionalAnimation
- LoopingAnimation
I originally did this:-
public void QueueUpAnimations(params string[] anims)
{
//Queue up animations
animation.wrapMode = WrapMode.Once;
animation[anims[anims.Length - 1]].wrapMode = WrapMode.Loop;
foreach (string anim in anims)
{
animation.PlayQueued(anim, QueueMode.CompleteOthers);
}
}
But the final animation never looped.
So i then had to more forcably set the wrapmode by setting up animation events to tell me when each animation starts and used this:-
string m_sCurrentAnimation = "NOT SET";
bool m_bSetWrapModeOnStart = false;
string m_sAnimationOnStart = "NONE";
public void QueueUpAnimations(params string[] anims)
{
//Queue up animations
animation.wrapMode = WrapMode.Once;
foreach (string anim in anims)
{
animation.PlayQueued(anim, QueueMode.CompleteOthers);
}
//Setup for final animation's wrap mode
m_bSetWrapModeOnStart = true;
m_sAnimationOnStart = anims[anims.Length - 1];
}
void OnAnimationStart(string animationname)
{
m_sCurrentAnimation = animationname;
if (m_bSetWrapModeOnStart (m_sCurrentAnimation == m_sAnimationOnStart))
{
animation.wrapMode = WrapMode.Loop;
m_bSetWrapModeOnStart = false;
}
}
And now it works fine the first time after I start the scene, the default Idle animation runs up to its last frame, then the transitional animations are played, then the final animation loops around. nice. But every time after that I do it, the current animation does not continue and the first transitional one starts immediately.
I feel like im trying to jump through hoops to achieve this very simple task of animation queuing… Is there a correct way that I should be doing this? I must be understanding the system incorrectly.
Many thanks in advance