- Home /
OnTriggerExit2D, OnTriggerEnter2D is not working
Hello,
I just spend hours on internet to find why functions are not working but I didn't find answer. Functions looks like that: void OnTriggerEnter2D (Collider2D col) { Debug.Log (" It is Working!!"); if (col.gameObject.tag == "ScoreChecker") { Debug.Log (" It is Working!!"); } }
void OnTriggerExit2D (Collider2D col) {
Debug.Log (" It is Working!!");
if (col.gameObject.tag == "ScoreChecker") {
}
}
And screenshots of Ball and Trigger:
Answer by cvid · Mar 25, 2018 at 03:43 PM
You should add the BoxCollider2D component on a ball also.
Answer by $$anonymous$$ · Mar 25, 2018 at 03:51 PM
Make sure you put the script on a gameobject that has a 2d collider on it with is Trigger not checked.
Actually is not correct. Is Trigger should be checked on GameObject with script. Otherwise OnTriggerExit2D / OnTriggerEnter2D never will be called. Ins$$anonymous$$d of it OnCollisionEnter2D/OnCollisionExit2D will be used. And in addition you can't use a collider with zero sizes.
oof i didn't even pay attention to what i was reading and didn't notice that he was trying to use a trigger, my bad.