OnCollision Problem

Lads,
I’m trying to set up an OnCollision script so that falling chunks of debris will make a little puff of smoke particles and then be destroyed when touching the ground. I think the script looks pretty good, but I’m missing something. In actuality what is happening is that all debris objects simply disappear when I start the game. Any ideas?:

var explosionPrefab:Transform;

function OnCollisionEnter(collision: Collision) {

if (collision.gameObject.tag == “Terrain”)

Instantiate (explosionPrefab,transform.position,transform.rotation);

Destroy (gameObject);
}

Thanks,

Stef

At first I didn’t see it, because your post was so badly formatted, but then I realised-

You’re missing brackets! This means that as soon as the object collides with anything, it immediately deletes itself, without even instantiating the explosion. Try this instead-

function OnCollisionEnter(collision: Collision) {

    if (collision.gameObject.tag == "Terrain")
    {
        Instantiate (explosionPrefab,transform.position,transform.rotation);
        Destroy (gameObject);
    }
}