How to destroy object after animation

I've made an object and when the player has pick it up, rise it up and stop it out of screen. But because you can see the shadow of that object, I will destroy it after the animation has played. But how can I do this whit Unity and C#?

Just destroy is just like this:

Destroy(gameobject);


and start an animation like this:

private Animator _anim;           // global variable
_anim = GetComponent<Animator>(); // in start() methode
_anim.SetTrigger("Picked");       // in other methode


You could do this by checking the current state of the Animator. Add an additional state that your animation will transition to and then check if the animator reaches this state using AnimatorStateInfo.

Or you could just use AnimationEvents

The best way in my opinion is to wrap the functionality and use a callback. This way you could reuse the code as well.

animatorBox.Trigger("Picked", () => {
Destroy(gameObject);
});

• The animatorBox is that another class then the Animator-class I has used, sir? – H. Pauwelyn Jan 1 '16 at 8:10
• Yes. This was just to show how you could do it using a wrapper class. The functionality in this class could for example use AnimatorStateInfo to check for completion. – Mattias Jan 1 '16 at 10:26

I've found also a way to do it:

// other code
anim.SetTrigger("Picked");
Destroy(gameObject, 2f);

• Sure. But then you are just asking how to delete a gameObject after x time. – Mattias Jan 3 '16 at 12:27