Alex RED Alex RED - 18 days ago 8
C# Question

Unity check if 2D objects in an array collide without OnCollisionEnter

I have Rigidbody2D and 2D colliders attached to my GameObjects. Is there a way to check if there is a collision between any two of my objects? I found a way: method OnCollisionEnter(), but I want to check for collision in a specific time between specific objects, but not between all. Is there a way to do that? Thanks in advance!

Answer

You could create a array stores links to objects collided with this object, and then just add links in OnCollisionEnter and remove links in OnCollisionExit. So you will be able to check if one object's array contain link to the second, if it is - theese two objects are collided in this moment.