Collider script refuses to work

I am making an Android game, and when the player touches a coin, it adds it to the score and destroys the coin object. But the code refuses to work, and I don’t know why. The coin has a mesh collider on it, and I thought maybe that was the issue. So I tweaked the code to detect rocks instead, which have sphere colliders on. Still no luck.

var PlayerCoins : int;
var CoinText = "Coins: " + PlayerCoins;

function OnTriggerEnter(other : Collider)
{
	if(other.tag == "coin")
	{
		PlayerCoins +=1;
		CoinText = "Coins: " + PlayerCoins;
		Destroy(other.gameObject);
	}
}

Hard to know exactly, but here’s a guess.

You might need to use OnCollisionEnter…

I imagine that your Player object is not using a trigger collider, but perhaps your coin object is. Therefore, since this script is attached to the player, you should use OnCollisionEnter. You would use OnTriggerEnter if the script was attached to an object with a trigger collider.

If you are working with 2D colliders…

You should use OnTriggerEnter2D or OnCollisionEnter2D.

Make sure your coin game object definitely has the tag “coin”.