- Home /
Trying to make an animation delay between each loop
Hello! So I have been trying to make an animation play, stop for a bit, then resume playing, and do that forever.
I have tried using plain code ( which requires animations to be in legacy and don't work in the animator), animation events (by making it call a function after every loop that resets a parameter to not allow a blank state to transition to the actual animation state and back but that doesn't work), animator parameters, animator transition conditions, animation events, and no success.
This sounds so simple and yet is so hard to find an answer to. Suggestions on how to do this sort of thing would be appreciated. Thanks in advance!
Answer by raincrowgames · Feb 08, 2019 at 10:00 PM
Animator anim;
void Start()
{
StartCoroutine(PlayAnimation());
}
IEnumerator PlayAnimation()
{
while (true)
{
anim.SetBool("play", true);
yield return new WaitForSeconds(1);
anim.SetBool("play", false);
}
}
Assuming you have animator set properly.
oh yes I did it! For anyone wondering, I made an animationEvent at the last animation keyframe, and set it to my function (you have to assign the script at the animation event in the inspector too). In my script, I did this (as @raincrowgames said):
public void IncrementAnimationTimer()
{
StartCoroutine(WaitForABit());
}
IEnumerator WaitForABit()
{
while (true)
{
anim.SetBool("play", true);
yield return new WaitForSeconds(2);
anim.SetBool("play", false);
}
}
and set up the animator like this:
Answer by keith801 · May 21, 2021 at 05:04 AM
If anyone else comes across this I needed to do the same thing but instead just added a blank image on the timeline at the end and another about 10 frames over, creating a gap in time depending on how long you want it to pause.
Your answer
Follow this Question
Related Questions
Is posible to make an universal transition tree for many GameObjects? 1 Answer
AnimationEvent has no receiver, but there is no AnimationEvent 1 Answer
Does Animate Physics mode execute animations only in FixedUpdate? 0 Answers
Set boolean to false when animation changes? 1 Answer
Get an Animator state inside an AnimationEvent callback of the last frame 2 Answers