Can't destroy object (166166)

Am i too annoyed already to think right? Because I CAN’T DO THIS! Ahh i am so furious! I am literally trying to figure out what am i doing wrong and i can’t anymore ‘-’

I want to make a prefab/object be deleted after a few seconds. Like, 1… 2… 3… it doesn’t exists anymore. But i can’t. I receive a “Uknkown Identifier” error everytime i change the “gameobject” in the script to “suit”.
SUIT is the name of the thing i want to destroy. If i just leave the line Destroy.gameobject as gameobject, it will not be destroyed. What’s wrong?

Here’s my script. It’s in Javascript. Sorry if i did not explain right, but i am really angry right now. It’s kinda ridiculous. Oh, the pragma strict actually have a # but i had to delete it in this text bcs it would stay giant and in bold

pragma strict

var delay = 2.0; //This implies a delay of 2 seconds.

function WaitAndDestroy(){
yield WaitForSeconds(delay);
Destroy (gameobject);
}

I'm a C# dev so not sure about this but i think unknown identifier means you misspelled "suit".

@Zitoox Just use it Object.Destroy(gameObject, 2.0f);

@Zitoox var delay = 2.0; //This implies a delay of 2 seconds. function WaitAndDestroy(){ yield WaitForSeconds(delay); Destroy (gameObject); } Call this function when you want to destroy it.

http://docs.unity3d.com/ScriptReference/Coroutine.html

[70913-original.png|70913]It's basically this. It's in Javascript. Actually, i deleted it and rewrited so many times i don't even know if this is correct or it's wrong. There's always a problem. You know, i don't even care anymore. I am starting to think it's a VERY BIG PROBLEM WITH MY UNITY. Because this fucking engine keep saying EVERYTHING is a unknow identifier! Literally. I am still receiving the same error. [70912-daaa.png|70912]

1 Answer

1

Not sure how you should be using Coroutines in Javascript so here is a solution using invoke

Invoke("DestroySelf", 2);

function DestroySelf() {
	Destroy(gameObject);
}

If that doesn’t work there is probably something else going on and I suggest posting your whole script as well as the line numbers that the errors are on.

You can specify the duration in Destroy, you don't have to invoke it to delay it... Destroy(gameObject,2);

![alt text][1]It's basically this. It's in Javascript. Actually, i deleted it and rewrited so many times i don't even know if this is correct or it's wrong. There's always a problem. You know, i don't even care anymore. I am starting to think it's a VERY BIG PROBLEM WITH MY UNITY. Because this fucking engine keep saying EVERYTHING is a unknow identifier! Literally. I am still receiving the same error. ![alt text][2] [1]: /storage/temp/70913-original.png [2]: /storage/temp/70912-daaa.png