Is there a way to queue animations based on button presses?
_
Example: the a button plays anim1 while the b button plays anim2.
So if I make this combination (a,a,b,a) then the animations while play accordingly one after the other in that exact sequence.
You could use a coroutine, paired with a check to see if anim1 has finished playing, before playing anim2. Here’s a simple example:
public Animator Animator;
IEnumerator QueueAnimation(string thisClipName, string nextClipName)
{
Animator.Play(thisClipName);
// Wait till it's finished
while (Animator.GetCurrentAnimatorStateInfo(0).IsName(thisClipName))
{
yield return null;
}
Animator.Play(nextClipName);
}
When the coroutine is started, for example like: StartCoroutine("Anim1", "Anim2");
, the first animation clip is played, then the second, after the first has finished. You can convert this into a continuous method that loops through a list of strings as such:
public Animator Animator;
public List<string> QueuedClips;
IEnumerator PlayQueuedAnimations(int index)
{
// Exit once all queued clips have been played
if (QueuedClips.Count <= index)
yield break;
string thisClipName = QueuedClips[index];
Animator.Play(thisClipName);
// Wait till it's finished
while (Animator.GetCurrentAnimatorStateInfo(0).IsName(thisClipName))
{
yield return null;
}
StartCoroutine(PlayQueuedAnimations(index + 1));
}
Hope that’s clear @Mrroundtree22
I dont understant how it work because of " while & this" what does it means ? i’m so confuse