- Home /
Delete Explosion After 1 Second Script Not Working
I wrote a small script that is supposed to destroy the attached gameobject in 1 second, but it keeps saying there is an error. Here is the error: Assets/DestroyExplosion.js(4,36): BCE0044: expecting :, found ';
Here is the script:
function Start () {
WaitForSeconds (1);
{
Destroy(gameObject);
}
}
Answer by Kiloblargh · Dec 08, 2013 at 07:55 PM
Too many brackets.
function Start () {
yield WaitForSeconds (1);
Destroy(gameObject);
}
Consider using an object pool and setting active / inactive instead. Instantiating and destroying 1 second apart every time something explodes will lag your game.
Thanks, this works perfectly for what I am doing. Thanks for the advice too.
Answer by Dunkelheit · Dec 10, 2013 at 09:56 PM
I guess you don't have to use waitForSeconds
function. Instead of that, try to use this one:
Destroy(gameObject, 1f);
Your answer
Follow this Question
Related Questions
Explosion before destroying 2 Answers
how can I destroying a spawn object ? 1 Answer
UI Object is there but can't destroy it. 0 Answers
Instantly Destroy Surrounding Objects (Grenade) 2 Answers
How to destroy an instantiated object 2 Answers