How do you destroy a gameobject?

I am sure it is very simple, and I know I should know how to do it, but how do you take a gameobject out of the game in javascript? This is obviously critical, and I need to know how for my game. Help will be very appreciated.

If you want it destroyed, just use the Destroy function.

Destroy(GameObject);

http://unity3d.com/support/documentation/ScriptReference/10_reference.Classes.html

Destroy (this);

No, that just destroys the script instance. And now that I look above…

You need a lowercase g.

Hey, just giving the generic version. If you’re destroying anything, just stick the variable for the Game Object in place of the GameObject.

Destroy(this.gameObject);

the ‘this’ is redundant, but it illustrates what’s going on better :wink:

Cheers

So does Object.Destroy(this.gameObject);, and so would a comment, but only (potentially) to somebody who didn’t know what was being done to begin with. You could even offer Object.Destroy((this as Component).gameObject); if you wanted to be extremely pedagogical. (Hopefully all of this has been helpful to the OP, at least!)

Now you’re just confusing the poor guy.

Destroy(gameObject);

this will destroy the game object that a given script is attached to.