2d destroy script

Hi,

I’m new to Unity and am trying to create a 2d puzzle game. I have two sprites as objects, one called ‘player’ and one called ‘coin.’ They both have 2d box colliders and 2 rigid bodies, and are both on the same plane. The ‘coin’ sprite IsTrigger is turned on. I have the ‘player’ sprite tagged as “Player.” This is the script I attached to the ‘coin’ object and nothing happened:

#pragma strict

function OnTriggerEnter (other : Collider)
{
	if(other.tag == "Player")
	{ 
	Destroy(gameObject);
	}
}	

Every time I press PLAY, the ‘player’ just passes over the ‘coin’ and nothing happens to it. What am I missing here?
Please and thank you to those who help me out, :slight_smile:

SIncerely,
very confused

The main issue is that OnTriggerEnter() is a 3D function. You need to use OnTriggerEnter2D() for 2D collision. I assume that the player is a non-kinematic Rigidbody2D.