- Home /
Firing triggers and playing animations in sequence
Let's say there are four animation states, A, B, C, D on two different layers. States A and B are on layer 1 and states C and D are on layer 2. Now, I want to play A and C together and then play B and D by firing their corresponding triggers. The way I have tried to do this is store the triggers for the pair of animations I want to play together in a dictionary as key and value pairs. Here is some example of the implementation I have tried so far:
//Dictionary to hold the triggers for the animation pairs I want to play together
Dictionary<string, string> triggers = new Dictionary<string, string>();
//Add triggers to dictionary
//......
//....
foreach (var key in triggers.Keys)
{
string value;
if (triggers.TryGetValue(key, out value))
{
//play the pair of animation in layer 1 and layer 2 e.g A and C
animator.SetTrigger(key);
animator.SetTrigger(value)
}
}
However, when I use the above approach, the order of the animations I want to play is reversed. That is, the animator plays B and D, and then A and C. In general, the idea this to play pair animations from two different layers in a given order.
So how can I achieve this? Is there any way I can do this in Unity?