OnDestroy collision detect

Hi !

All i want to do is when the function OnDestroy is called i want to know if the object that is colliding with it has the same tag, but if i do like this:

function OnDestroy () {

   if(gameObject.collider.tag == gameObject.tag)
   {
      Destroy(Collision.collider);
   }

}

it's totally wrong right ?

HELP ?

OnDestroy doesn't just happen, it is called after you call Object.Destroy. (Or when the scene is unloaded.) Assuming you call Object.Destroy from your OnCollisionEnter, either check the tags then, or save the Collision in a class variable so you'll have it during OnDestroy.

private var isClicked : boolean = false; 

      function OnMouseDown()
    {
    isClicked = true;
    }

     function OnCollisionEnter (other : Collision)
        {
        if (other.gameObject.tag == gameObject.tag && isClicked)
        {
        Destroy (other.gameObject);
        Destroy (gameObject);
        }
        }

Once again, haven't tested this, but using a boolean to test for a mouse click may be the simplest way to go.

let me make myself clear:

for example you have 3 blue and 3 red and 3 yellow balls all colliding. What i really want is when i click in a ball it has to check if the collider has the same tag and destroy the two or three colliders.

For example : i click in a blue ball and if there is another blue ball colliding with it they will be destroyed.

All the code that i've got in each ball it's :

function OnMouseDown () {

Destroy(gameObject);

}

function OnDestroy (){

if(gameObject.collider.tag == gameObject.tag)
{
    Destroy(Collision.collider);

}

}

And i'm getting "An instance of type 'UnityEngine.Collision' is required to access non static member 'collider'."

In each ball, keep a set of currently intersecting balls with the same tag. Add to this list in OnCollisionEnter and remove from it in OnCollisionExit. In OnMouseDown, delete all balls in that list.