- Home /
How to change animations every 60 seconds through the animator in Unity3D and C# Visual?
I made several animations clips on a character through the animator in Unity.
And I added a countdown timer which is a Text Ui component from a canvas. It is initially 00, but when I play the start button it decrease from 60 by 1 to 0, during which time animation1 repeats. When the timer reaches 0 I want the animation to change, so from animation1 to enter animation2.
Above is the code for the timer and the if condition where I managed to do this with a bolean parameter from animator and an if condition in a C # script.
But when the timer ran out a second time and reached 0 I want it to go from 'animation2' to 'animation3' and the parameter 'change' to become false and the parameter 'change1' to become true. And so, every time the timer reaches 0 another animation to load.
Is there any way I can do this?
Answer by Llama_w_2Ls · Jan 26, 2021 at 12:36 PM
You could use Animation.Play("animClipname");
and Animation.Stop();
to play the next animation clip in the animation. For example:
public Animator animator;
void Start()
{
StartCoroutine(PlayAnimations(60));
}
IEnumerator PlayAnimations(float time)
{
int index = 0;
while (true)
{
yield return new WaitForSeconds(time);
animator.Stop();
animator.Play("AnimationClip" + index.ToString());
index++;
}
}
Your answer
Follow this Question
Related Questions
2D Animation does not start 1 Answer
Issue with mecanim playing an animation using setbool 1 Answer
Imported Blender Animations not Working 2 Answers
Error console animator 0 Answers
Animation in android game not working 2 Answers