- Home /
How do you destroy a clone ?c#
hey guys i need some help with trying to destroy these clones after a certain period of time. i need them to be destroyed so that there isn't a clutter of them. here is my script. the script is attached to what is being cloned. thanks for your guys help
public class destroyenemy : MonoBehaviour {
private float timerfive;
void Start () { }
// Update is called once per frame void Update () { timerfive += Time.deltaTime; if (timerfive > 3) { Destroy(gameObject); } } }
Answer by fafase · Aug 24, 2012 at 10:19 PM
you can use Invoke:
function Start(){
Invoke("DestroyIt",10.0f);
}
function DestroyIt(){
Destroy(gameObject);}
attach that to the object prefab, it automatically gets destroyed after 10s
void Start(){
Invoke("DestroyIt",10.0f);
}
void DestroyIt(){
Destroy(gameObject);}
that is C#, please learn basic program$$anonymous$$g before co$$anonymous$$g here.
Also that destroys the main object, which would stop new spawns
Please click the check if you feel his answer is correct
Your answer
![](https://koobas.hobune.stream/wayback/20220613080134im_/https://answers.unity.com/themes/thub/images/avi.jpg)