Destroy gameObject

Hi. I want to destroy gameObjects that is connected to the script.

This is an example script:

var Bomb : GameObject; var Ammo : GameObject;

function killBomb() { Ammo = Bomb; Ammo.Destroy() <-- THIS IS WHAT I WANT TO DO, but i doesnt work. }

Anyone have any idea how to do this?

It sounds like you have Bomb hooked up to the game object incorrectly. Make sure you are assigning bomb to a living game object (something that is in the current scene). Make sure you are instantiating and/or assigning the Bomb object. Your redundancy of assigning ammo to bomb is pointless also. Maybe you wanted to instantiate a bomb instance, assign ammo to that instance, and then destroy it? Once you fix that just do GameObject.Destroy(Ammo);

Destroy (bomb);

simple and easy. if you want to access your own gameobject you should write.

Destroy (this.gameobject); //kills yourself

so destroy method destroy the passed argument and not the caller of itself.

var Bomb : GameObject; 
var Ammo : GameObject;

function KillBomb()
{
   Ammo = Bomb;
   Ammo.Destroy();
}

This looks a little better :P

Destroy (Bomb); <-- this dosent work, I get the message: 

  Destroying assets is permitted to avoid data loss.

GameObject.Destroy(gameObject); I have tried these variations of this:

GameObject.Destroy(Bomb);
Bomb.Destroy(gameObject);

and none of them are working.

Update! A more complete script:

var Bomb : GameObject; 
var Ammo : GameObject;
var Stone : GameObject;

Button1()
{
   Ammo = Bomb;
   KillAmmo();
   Instantiate (stone)
}
Button2()
{
   Ammo = Stone;
   KillAmmo();
   Instantiate (Bomb)
}

function KillAmmo()
{
   Ammo.Destroy(); <-- This is what I want to do.
}

Maybe you wanted to instantiate a bomb instance, assign ammo to that instance, and then destroy it?

Yes, that is what I want to do.

Thanks for all your help, I got it to work :D