- Home /
2D Collisions not registering at all.
I have been trying to figure this out for hours and I swear it should work but it just refuses to.
I have two 2D objects on the same layer at the same z position, both of which have 2D colliders and one of which (player) has a 2d rigidbody while the other is ticked as a trigger, with the following script:
void OnTriggerEnter2D(Collision2D col) {
if (col.gameObject.tag == "Player")
{
Print ("Collision!!!");
Destroy (col.gameObject);
}
}
However no matter which object I attach it to, where I put the function, what I try to change it to, nothing happens when they collide? The tag is definitely right and I have tried it without the if statement as well to see if it is working.
If anyone has any idea of what else it could be that would be amazing :)
Answer by robertbu · Sep 25, 2014 at 11:25 AM
OnTriggerEnter2D() takes a Collider2D, not a Collision2D as a parameter. Note for debugging, always put a Debug.Log() just inside the OnTriggerEnter2D() to see if it is getting called.
Your answer
![](https://koobas.hobune.stream/wayback/20220613163737im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Basic 2D cannon rotation code not working 1 Answer
Getting Started with 2d 0 Answers
Collision counter 2 Answers
How to use collisions with 2D Dynamic Shadows Plug-in in Unity? 0 Answers