Hi, so I have an Animator that has two animations, ‘Number 1’ and ‘Number 2’. They are not connected together, no transitions between them, both have loop times. Once the Scene starts, animation ‘Number 1’ is playing by default. Now, I would like that after five seconds, Animator switches to the animation ‘Number 2’ and keeps playing that one. What would the code for something like that look like… I’m using the latest updates, Unity 5.5.0f3 (64-bit). I’m looking for a C# script.
Thanx in advance.
So, I’ve managed to do it like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Change : MonoBehaviour {
IEnumerator Start()
{
yield return new WaitForSeconds(5f);
GetComponent<Animator>().Play ("Number 2");
}
}
But now I’m interested, what if we have an animation ‘Number 3’ as well, how do we add (or update) IEnumerator to change the state again to ‘Number 3’, after we have already used it for the above change? I know that you could do it by creating simultaneous scripts for each change and attaching to object, but that’s a bit crowdy…
In the animator window, click on a transition, then remove all parameters from the conditions section. Instead, check the “has Exit Time” option. The in the settings drop down menu right underneath, you can adjust the exit time to 5 seconds, along with some other transition options. Sorry I’m about 3 years late.
12 Likes