- Home /
Animation.CrossFade waiting for transition to finish
I am calling Animation.CrossFade inside OnMouseDown even to make a transition of animation state within 3 seconds interval. I want to destroy the game object right after the transition finished but not before that. Below is the code:
void OnMouseDown()
{
GetComponent<Animator>().CrossFade("statename", 3f);
Destroy(gameObject);
}
But it is being destroyed before the transition is done. How can I make it wait for the transition to finish, then destroy it?
$$anonymous$$ost probably yeild only works inside update methods. Destroy(gameObject,3); works.
Answer by Qasem2014 · Jan 02, 2015 at 07:17 PM
<< Destroy(gameObject,3); >> destroy your object after 3 second .
but maybe you need wait until this line complete :
GetComponent<Animator>().CrossFade("statename", 3f);
SO you need yeild
im not sure and i don't use yeild before !
you can close the question if your problem solved =D by click on Green tick
Oh, I assumed this answer as a comment before! Looks like I commented on my own question! I didn't notice, sorry. :P
Your answer
![](https://koobas.hobune.stream/wayback/20220613175429im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Best Way to script Mecanim Animation CrossFade? 0 Answers
How to play multiple animations on the same game object. 2 Answers
2D Animation does not start 1 Answer
Animator.CrossFade or Animator.CrossFadeInInFixedTime does not play animation after crossfading. 0 Answers
How can I smoothly transition my player camera from manual control into an animation? 1 Answer