Collision script

In my project I have a cube and spheres falling from the sky. I want the spheres to destroy the cube on collision, Here is my script attatched to the sphere:

function OnCollisionEnter ( collision : Collision) {

if (collision.collider.gameObject.Find("Player"))

Destroy (GameObject.Find("Player"));

}

The problem here is the sphere destroys the cube whenever it hits any rigidbody. What am I doing wrong?

try this:

function OnCollisionEnter ( collision : Collision) {

if (collision.collider.name == "Player")

Destroy (GameObject.Find("Player"));

}

Your code was checking if an object (called "Player") even existed in the whole scene. But mine checks if specifically the colliding object's name is "Player".

it should be:

function OnCollisionEnter ( collision : Collision)
{
    if (collision.gameObject.name == "Player")
        Destroy (collision.gameObject);
}

So you check what collided, then destroy it if it's called Player

Your original code just checked if there was an object called player, then destroyed it