Bug With Collision Detection In Unity 3?

Sorry if this seems to be a newbie question. However i seems to have problems detecting collision between my player and the gameObject i want to detect. Am i writing it wrong somehow?

function OnCollisionEnter(collision : Collision)
{
    Debug.Log(" i got u");

    if(collision.gameObject.Find("CarrotType1(Clone)") && getNos == 1)
    {
        Debug.Log("hello");
        //Destroy(targets);
    }

    if(collision.gameObject.Find("CarrotType2(Clone)") && getNos == 2)
    {
        Debug.Log("hello");
        //Destroy(targetz);
    }
}

it does not even output the "I got you" message in the Debug. Thanks in advance for any suggestions that i might be doing it wrong. :)

One thing to note: When using onTriggerEnter (this may also apply to collisions) the documentation says that both objects need either a collider or a rigidbody.

In my experience, this is not correct.

This is only true if BOTH Objects are moving.

If one of the objects is standing perfectly 100% still, then the other object will need to have a rigidbody as well.

Have you attached a rigidbody to either the player or the carrots? And a collider to both of them?

Also, your if statement doesn't make that much sense. I would use something like

collision.collider.name == "CarrotType2(Clone)"

Does this solve the problem?

Try using THIS Unity3D collision method. It should make life a bit easier:

It's a simple check for looking if the collision box of your moving charactercontroller has come into contact with something above below etc. Little else is needed for simple collision detection

Thanks again for the suggestion. However i tried both ways. and it doesnt work also. ); This the whole code for this class. maybe its more informative. =/

class Collisions extends StageWaypoint {

public var targets : GameObject;
public var targetz : GameObject;

private var thisNum : int;
private var getNos : int;

function Awake()
{
}

function Start()
{       
    //Debug.Log(targets);
    //Debug.Log(targetz);
    //Debug.Log("hellosssss");
}

function Update()
{
    targets = GameObject.Find("CarrotType1(Clone)");
    targetz = GameObject.Find("CarrotType2(Clone)");
    getNos = thisNum;

    //Debug.Log(getNos + " this is rec");
    //Debug.Log(targets);
}

function OnControllerColliderHit(collision : ControllerColliderHit)
{
    Debug.Log(" i got u");

    if(collision.collider.name == "CarrotType2(Clone)" && getNos == 1)
    {
        Debug.Log("hello");
        Destroy(targets);
    }

    if(collision.collider.name == "CarrotType2(Clone)" && getNos == 2)
    {
        Debug.Log("hello");
        Destroy(targetz);
    }

}

function recNum(no : int)
{
    thisNum = no;
}

}