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:

var collision = ammo.GetComponent<ParticleSystem>().collision; collision.collidesWith = desiredLayers; This is the correct code if you want to assign a new value to the collidesWith property in the particle system collision module (as per the docs, in the Update function in the example).

2 Answers

2

You should add the BoxCollider2D component on a ball also.

Thank you!! Added BoxCollider2D and magic happens :D

@richardkettlewell I just tested both of the codes (yours and mine) and they both work perfectly. As I see they do the exact same thing so I still don't understand why my code is "incorrect" while yours is not?".

Make sure you put the script on a gameobject that has a 2d collider on it with is Trigger not checked.alt text

Actually is not correct. Is Trigger should be checked on GameObject with script. Otherwise OnTriggerExit2D / OnTriggerEnter2D never will be called. Instead of it OnCollisionEnter2D/OnCollisionExit2D will be used. And in addition you can't use a collider with zero sizes.