Using C# and I am trying to have an animation play once, then move to a second animation. The current set up I have is obviously not going to work, I know I need to use a for loop for how i am trying to go about this, but I forgot. This is the script I have right now.
void Animation()
{
robot.animation.Play("idle01", PlayMode.StopAll);
plays += 1;
if(plays >= 1)
{
robot.animation.Play("dance", PlayMode.StopAll);
}
}
for(var I : int=0; I < thisValue; I++;)
{
///do stuff
}
void Animation()
{
for(int plays=0; plays < VALUE;)
{
if(plays ==0)
{
robot.animation.Play("idle01", PlayMode.StopAll);
}
else
{
robot.animation.Play("dance", PlayMode.StopAll);
}
plays += 1;
}
}
A for loop might not be the best option to play an animation right after the first one is done, unless you not trying to play the entire animation first. In that case disregard my comments.
You should be using a Coroutine to get the time for the first animation, wait, then play the second.
IEnumerator PlayAnimation(string animationName1, string animationName2)
{
animation.Play(animationName1);
yield return new WaitForSeconds(animation[animationName1].length);
animation.Play(animationName2);
}
Then call the function using this,
StartCoroutine(PlayAnimation("Animation1", "Animation2"));
Something like that should do the trick.
You can always Queue the animations up → Animation.PlayQueued Documentation