OnTriggerEnter2D not triggering
I have a ball and player objects, both have collider2D's and rigidbody2D's. im trying to use the following c# code to detect collisions:
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
{
Debug.Log("Hit Player", gameObject);
}
}
but the code doesn't get triggered by collisions. unless one of the objects is set to behave as trigger then the objects pass through each other (therefore don't collide in the traditional sense) but the console will log the collision "Hit Player".
Im sure its a simple problem, but I would appreciate some help.
Answer by Microsparky · Apr 07, 2016 at 07:16 PM
Thanks, figured it out today. nether object is a trigger they both have colliders tho. here is the code i used:
void OnCollisionEnter2D(Collision2D otherCollider)
{
if (otherCollider.gameObject.tag == "Player")
{
Debug.Log("Hit Player", gameObject);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612074327im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
OnTriggerEnter/Exit Rapid Firing? 0 Answers
If "OnTriggerEnter" then "another OnTriggerEnter" ? 2 Answers
Trigger for every tilemap square. 1 Answer