- Home /
OnTriggerEnter2D not working on second Trigger events
I have a box collider 2D with tag "Collider" which has isTrigger = true and in my player object I have a rigidbody 2d and a box collider 2d.
the code below is within a script within my player object Now the onTriggerExit2d runs the first time just fine same as the enter but if i try to exit and enter the object again this code doesn't run and i don't know why this is.
void OnTriggerExit2D(Collider2D hit)
{
print("Collider Exit");
if(hit.gameObject.tag == "Collider")
{
print("Left Collider");
}
}
void OnTriggerEnter2D(Collider2D hit)
{
print("Triggered Entered");
if(hit.gameObject.tag == "Collider")
{
print("Entered Collider");
}
}
EDIT: Ok I was dumb it is working i just expected my console to write each line as it was told to and not stack matching prints ¬_¬ (I hadnt slept for 24 hours when i posted this)
Hm... does it work when you use CompareTag ins$$anonymous$$d?
hit.gameObject.CompareTag("Collider")
Edit: I just tried it out and it works in both ways in may setup. $$anonymous$$aybe you change your collider object or something. can you post your hole palyer script?
Answer by Kaldhu · Nov 18, 2013 at 05:38 PM
This Has Been solved (well there never was an issue)
Your answer
![](https://koobas.hobune.stream/wayback/20220613122124im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Method doesn't work when called in other script 0 Answers
OnTriggerEnter 1 Answer
How can i detect hits from enemies inside of a player? 1 Answer
How to make kinematic platform trigger events 0 Answers
OnTriggerEnter2D with multiple objects 0 Answers