a question about scripting

Hi,

i want after a game object played it’s animation destroy. i have written this code but the game object doesn’t destroid!! what is wrong?

GameObject Box = GameObject.FindGameObjectWithTag(“box”);
Box.animation.Play(“idle”);

if (!Box.animation.isPlaying)
{
Destroy(Box.gameObject);
}

Destroy(Box)

has no effect. the object still remains!! :shock:

that’s probably because you never stop the animation on the box and it keeps playing forever.
make sure that the if-section gets called properly (for example by putting a simple print() in it) and that the animation stops at a certain point

can you play describe more?
i’m basic at unity.

thanks

if (!Box.animation.isPlaying)
{
  print("destroy");
  Destroy(Box.gameObject);
}

if “destroy” appears in your console, it means that Destroy() isn’t working properly. if it never appears, it means that isPlaying is always true

“destroy” never appears. how can i stop the animation after playing finish make is playing false?

thanks