- Home /
Script Help -- OnCollisionEnter2D
I have 2 sprites, each with 2D colliders attached. On my player sprite I am trying to trip the OnCollisionEnter call but I can't seem to get anything to return on my console for debugging. I have my two attempts at running the collision detection below. Thank you for you help!~
void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "Enemy") { ///coll.gameObject.SendMessage("ApplyDamage", 10); Debug.Log ("beep"); }
void OnCollisionEnter2D() { Debug.Log ("beep"); }
Seems like your gameobject doesn't have Rigidbody2D component attached.
Answer by MelvMay · Feb 13, 2017 at 03:03 PM
If you don't add a Rigidbody2D then the collider is assumed to be static and not should be moved. Static colliders do not collide with other static colliders which makes sense if you consider that they should not be moved.
Add a Rigidbody2D and use either a Dynamic or Kinematic body-type. You can read up about the body-type here (click on the RigidbodyType2D for more information).