Destroy the current GameObject?

How do you destroy the current GameObject? (the one the script is in)

`Destroy(GameObject)` doesn't work nor does `Destroy(this)` ... The latter seems to destroy the construct, but does not remove the actual GameObject onscreen...

When using `Destroy(gameObject)`, it seems I am no longer able to instantiate new ones if I kill off the only prefab on screen (even from another script).

BTW - what is the difference between `GameObject` and `gameObject` and `this`?

Destroy(gameObject) is the correct way to the GameObject your script is attached to.

When using Destroy(gameObject), it seems I am no longer able to instantiate new ones if I kill off the only prefab on screen (even from another script).

I'm not sure what you mean by 'on screen'. Prefabs do not exist inside the scene, they are in the project. You should not be destroying Prefabs.

what is the difference between GameObject and gameObject and this?

GameObject is a class.

gameObject is a property you can call on a MonoBehaviour to the the GameObject instance that Monobehaviour instance is attached to.

this is the instance of the class the code is in.

Have you tried: Destroy(this.gameObject);

Destroy(gameObject) does (should) gt rid of attached gameobject

From a diff object you could say


Or something like that.

this gameobject is nothing but in which gameobject you have placed that script...if you use Destroy(this.gameObject);

it'll destroy the gameobject in which you have placed the script....

Destroy(gameObject)- it'll destroy particular gameobject what you have specified.

try to store instantiated gameobject name as "clone" and destroy that clone object using Destroy(clone); it'll destroy all objects from origin.

**The answer.

I tried this and is working.

Jag har provat det och den fungerar.

جربتُ هذا السطر و نجح معي


Ok here you go

This script goes with the gameobject that is Instantiating the gameobject.

var bullet : GameObject;

var backup : GameObject;

function Update () {
if(Input.GetKey(“a”)) backup = Instantiate(bullet, transform.position, transform.rotation);


The bak up file will make it to were if the gameobject gets destroyed then it will still be able to be Instantiated.

Im running out of time bu if you want to know more simple ways Email me

Email :

I will explain the simplest way to do it cause it is simple

So pleas Email me… :)(: …