OnCollisionEnter doesnt seem to work, i want to make objects dissappear when i come in contact with them?

var piecesCollected : int = 0;

function OnCollisionEnter(theCollision : Collision){

if(theCollision.gameObject.tag==“piece”) {

Destroy(gameObject);
}
piecesCollected++;

}

function OnGUI () {
GUI.Label (Rect (10, 10, 100, 20), piecesCollected.ToString());
}

You should probably do this:

Destroy(theCollision.gameObject);

Instead of this:

Destroy(gameObject);

Also, one of the colliders must have a Rigid Body component.

Add the Rigidbody in your Player Object or in which object by you collect pieces.

Check the tag in which object you added. Tag must be assigned with piece objects.