How to let animation play to the end before playing the next one using button
ABSOLUTE BEGINNER...
I know this question is been ask 100.000 times, but i cant get it to work.
Please see my setup and be so kind to help me out with this...
Project:
Right now my animations with buttons run perfect. The animations are looped and on press the next animation starts, perfect!
BUT.... the animations do not play to the end, on pressing the button, the next animation begins, without waiting for the running animation to play to the end.
Here is the code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FISH_ANIM : MonoBehaviour { private Animator Anim;
// Use this for initialization void Start() { Anim = GetComponent();
}
// Update is called once per frame
void Update() { }
public void Anim_turn_to_cam() { Anim.Play("Turn_to_cam", -1, normalizedTime: 0f); }
public void Anim_move_front_cam() { Anim.Play("Move_front_cam", -1, 0f); }
public void Anim_move_away_from_cam() { Anim.Play("Move_away_from_cam", -1, 0f);
}
}
what should i write after line e.g. :
Anim.Play("Move_away_from_cam", -1, 0f); .....
(yield did not work or i failed)
Thank you so much....
Answer by tormentoarmagedoom · May 06, 2018 at 09:16 PM
Good day.
You have the bool isPlaying, which will be true during animation, and false once the animation has finished
Bye!
Thanky you so much for your reply tormentoarmagedoom,
I think i did something wrong, here is my screenshot. Bool is not working.
When i press the button, animation is not playing to the end :(
Hello again!
Look at your image, at the inspector, you have a timeline of 2 animations called "move in front" and "turn away". From second 2.5 to second 5 is trying to execute both animations at same time... of course is not possible, the blue zone is what you really will see, so now, the "front in move" animation finishes at 2.5 seconds...
$$anonymous$$ove the "turn away" animation to the right!
Bye! :D
(Accept the anseert if helped) :D
Hi tormentoarmagedoom! Thank you again!!
I moved the clip as you said.
The "move_in_front_of_cam" clip is looping perfect, but when i click the button the next animation starts immediately without waiting for the clip "$$anonymous$$ove_in_front_of_cam" to play to the end.
Any other ideas?
When i click on the button, the clip should play to the end before the next animation starts.
Greetings...
Good day :D
I'm not expert with animations, you should take a look at some youtube tutorial, I'm sure the answers is out there! Take your time, and explore... is always the best option! aAnd sure will learn more thing you didnt expected.
Answer by BMD2018 · May 10, 2018 at 07:56 AM
Dear Unity Team,
can anybody help me out with this? I do not get it to work...
Please...
Dear B$$anonymous$$D2018 we are not unity $$anonymous$$m, we are users like you :D and you have thousands of manuals and tutorials aboput animations! go spend some hours learning!
Dear tormentoarmagedoom,
thank you for your reply.
God knows ive spend hours for this to get it to work. I watched all tutorials of this theme.
$$anonymous$$ost write the idea, but not the working code.
In Unity is this a solution:
animation.Play( ); yield return new WaitForSeconds( animation.clip.length );
but i am not a coder and C# is like chinese for me and i don't get it to work.
I haven't thought that this basic stuff is that complicated for me and to get help.
But thank you so much for your try.
Best regards,
B$$anonymous$$D2018