onCollision Destroy

Lads,

I have a stack of blocks and I’m trying to shoot one and have it disappear so the others will tumble down. I’m using:

function OnCollisionEnter(collision: Collider) {

Destroy ( this.gameObject );
}

…but still having problems getting it to work.

Any Ideas?

Thx,

Stef

I don’t really code in JavaScript, but I think I am safe to assume that when you reference this inside of Unity, it is referring to the instance of the script and not the game object itself. You should only have to call:

Destroy( gameObject );

to reference the gameObject to destroy. If the script is attached to each box, this would work. If it is inside of the “bullet” that you’re using to shoot, then you would have to call:

Destroy( collision.gameObject );