- Home /
The question is answered, right answer was accepted
Why won't they trigger collision?
I know it's a very vague question, but I have two objects colliding, they work just fine, but when I add another object to the scene (an NPC) it spontaneously can't detect the collision. My code looks like this: private void OnTriggerEnter2D(Collider2D collision) { if(collision.tag == "Floor") { floorCollisions = true; jump = initialGravity; } Debug.Log("LoOk At Me"); } private void OnTriggerExit2D(Collider2D collision) { floorCollisions = false; }
Upon further inspection, the code inside the if statement inside the OnTriggerEnter2D runs, but the Debug.Log() doesn't. Why is this happeneing? Why does enabling the NPC make the OnTriggerEnter not trigger? (It only triggers directly under the NPC) I checked the hitboxes and they're just fine.
Answer by PersianKiller · Sep 10, 2017 at 05:12 AM
I guess you forgot to make a condition for OnTriggerExit2D.
void OnTriggerExit2D(Collider2D collision) {
{ if(collision.tag == "Floor")
floorCollisions = false;
}
}
so floorCollisions always is true;
THAN$$anonymous$$ YOU--It's been a while since I posted this, but THAN$$anonymous$$ YOU, this must be the answer!