- Home /
OnCollisionEnter2D(coll: Collision2D) function not being triggered
I am making a game where an object with a 2D collider component follows a character and is meant to delete whatever it touches, in order to clear up objects that have gone off screen. Currently I am using some very simple code just to check for a collision, but the print statements are never exicuted. I know that the object is colliding with other objects, as I can see them colide from the scene viewer. all of the objects have 2D colliders some are box's some are circles and some are polygons. I have tried setting the deleter objects 2Dcollider to "is trigger" and "is not trigger" but neither has worked. The deleter object is an empty with a 2D BoxCollider and two scripts attached, the first is a script to follow the character, which merely changes the objects y coord to have it follow the character and the second one is the collision detection one shown below. Alternately if there is no fix, I could benefit from other suggestions on how to delet the objects when they move off screen. Thanks in advance.
OnCollisionEnter2D(coll: Collision2D){ print("###############################"); print(coll.gameObject.name); }