destroy on collision

hey everyone… im having some issues with getting my missile to be destroyed on its collision…

function OnCollisionEnter  (collisionInfo : Collision);

if (collisionInfo.gameObject.tag == ("block")
{
Destroy(gameObject);
}

thats the script i have attached to my missile, “block” is the tag of an item it will collide with

any help?

It does not trigger ?

Check whether the gameObjets with tag “block” also have a collider AND whether one or both of the objects have a rigidbody (IsKinematic off).

http://unity3d.com/support/documentation/Manual/Physics.html

thanks i actually just figured it out tho… i was making it way more complex then it had to be… simple enuff put this code on the missile prefab

function OnCollisionEnter () {

Destroy (gameObject);

}

works like a charm :smile:

You rewrote your script, right? I don’t think it would run that way. Here’s what I expect will run:

function OnCollisionEnter  (collisionInfo : Collision) {
    if (collisionInfo.gameObject.tag == ("block") 
    { 
        Destroy(gameObject); 
    }
}

And just to check that everything is triggering when it ought to, try this:

function OnCollisionEnter  (collisionInfo : Collision) {
    Debug.Log("collision occurred");
    Debug.Log("tag = " + collisionInfo.gameObject.tag);
    if (collisionInfo.gameObject.tag == ("block") 
    { 
        Destroy(gameObject); 
    }
}

Also, check the “collision detection matrix” (on the page AkilaeTribe referenced) to make sure the missile object type can bump into the block object type.

Aw man, I was writing while you were figuring it out. Never mind.