- Home /
OnCollisionEnter2D Not working!
function OnCollisionEnter2D(coll : Collision2D) {
if (coll.gameObject.tag == "Coin"){
Debug.Log("hit");
}
}
So i put this on a sprite with a 2d box collider (non trigger)and a rigidbody2d.
I have a sprite with a "Coin" tag and 2d box collider (non trigger)and a rigidbody2d.
When they collide its soposed to say hit in the console but nothing happens.
IT WORKS NOW
Are you simply sure the object which collide your coin also has a collider (non trigger) ?
Do you use layers ? If yes, check the collision matrix.
Answer by phoda · Jul 10, 2015 at 01:19 PM
void OnTriggerEnter2D(Collider2D col)
{
//If collided object is block
if (col.GetComponent<PolygonCollider2D>().tag == "Row")
{
//My script
}
}
My both objects have 2D collider and one have rigidbody but both are set to triger.
Hope this helps.
Your answer
Follow this Question
Related Questions
Large 2D polygon mesh levels 1 Answer
Moving BoxCollider2d with animation is not the right way? 2 Answers
Constant velocity when colliding - 2D 0 Answers
Make a gameobject Trigger Trigger Colliders but not Other Colliders 1 Answer
Unity2D, how to stop game when colliding with an object or speed is 0? 1 Answer