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:


and start an animation like this:

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

2 Answers 2


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", () => {
  • \$\begingroup\$ The animatorBox is that another class then the Animator-class I has used, sir? \$\endgroup\$ Commented Jan 1, 2016 at 8:10
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Mattias
    Commented Jan 1, 2016 at 10:26

I've found also a way to do it:

// other code
Destroy(gameObject, 2f);
  • \$\begingroup\$ Sure. But then you are just asking how to delete a gameObject after x time. \$\endgroup\$
    – Mattias
    Commented Jan 3, 2016 at 12:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .