How to make an object explode on collision?

Just as in this old topic http://answers.unity3d.com/questions/140468/how-to-make-an-object-explode.html,
I have downloaded the explosion framework and want to have the explosion on collision.

I have a ball and when this ball hits anything, it must be explode.
I have attached the detonator script and the script below to the ball.

#pragma strict

public var ball: GameObject;

function OnCollisionEnter()
{
    ball.GetComponent("Detonator").Explode();
}

Now I have the error “‘Explode’ is not a member of ‘UnityEngine.Component’”

Does that something to do with the fact that my script is javascript and the detonator script is c## ?

(I’m struggling with it for a couple of hours now and I think I’m overlooking something stupid).

overlooking yes… stupid? well that could be discussed :slight_smile: no im sorry that was not nice of me

if you check the unity script reference for the usage of OnCollisionEnter() you must in the a collision object into the function. Then from this collisionobject you can extract the information of what objects has collided and then what to do with it.

function OnCollisionEnter(collider : Collider){
    
    //if the collided object is the object with a name of ball
    if(collider.GameObject.name == "ball"){
        
        //then get the component detonate and call the function explode
        collider.gameObject.getComponent("Detonator").Explode();
    }
}

OnCollisionEnter

http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnCollisionEnter.html

Thanks for reply.

It still says that ‘Explode’ is not a member of 'UnityEngine.Component.

No problem to call me stupid because I think I did this before :sweat_smile: but I lost it.

Is it right that line 4 in your code must be:

 if(collider.gameObject.name == "ball"){

instead of

 if(collider.GameObject.name == "ball"){

bad: collider.GameObject.name
good: collider.``gameObject``.name

GameObject is a class
gameObject is an instance

…back to school :slight_smile:

Could it be that the detonator script is not accessible for some kind of reason?

Attach a empty GO to your object and instantiate a explosion/particle system from it.