issue with OnCollisionEnter; "if" statement necessary or not?

If an object (ex. cube) has OnCollisionEnter on it, should the following code work correctly if the object hits any other object?

function OnCollisionEnter(shotCollide : Collision)

{
Debug.Log(“hit”);

}

or do I have to write this:

function OnCollisionEnter(shotCollide : Collision)

{
if (shotCollide.gameObject.name == (“anyObject”))
{
Debug.Log(“hit”);
}

}

Both will/should work. Depends on what you want to achieve actually.

And also please wrap your code in [plain]...[/plain] tags when posting it into the boards.