Question by
$$anonymous$$ · Dec 05, 2019 at 03:59 AM ·
destroytagdestroygameobjectdestroy-clones
How do you make a destroy command with timer and with tag.
Hey everyone! How do I make code so that a gameobject with a certain tag, "pawn" deletes after 5 seconds? Thank you in advance.
My current code (Not Working...)
Destroy(GameObject.FindWithTag("pawn"), 5);
Comment
Best Answer
Answer by Larry-Dietz · Dec 05, 2019 at 04:23 AM
If you want it to be destroyed 5 seconds after it was instantiated into the scene, then in the Start method, in a script attached to the pawn, do a Destroy(gameobject, 5);
If you want to trigger the 5 second countdown in all pawns, from another script, then something like this...
foreach(GameObject go in GameObject.FindGameObjectsWithTag("pawn"))
Destroy(go, 5);
Hope this helps, -Larry
Your answer
![](https://koobas.hobune.stream/wayback/20220612215720im_/https://answers.unity.com/themes/thub/images/avi.jpg)