How to know how many objects OnCollisionEnter touches at the same time?

In my game when object hits a wall, or floor - a sound plays once.

It then checks what was the last tag touched, and it wont play the sound again until the tag is different.

I’m using OnCollisionEnter to detect these tags like “floor” or “wall”. It works fine until the object is touching both “floor” and “wall” at the corner, at the same time. So the object is still, in the corner, but the tag changes between “floor” and “wall” and the sound plays on and on.

Is there a way to count in OnCollisionEnter how many objects it’s touching? Then if I knew that there are 2 or more tags touching I would know to check all tag names involved so the sound would be played only once.

sure is…

Just put these in your collision object script…

int touchCount = 0; //Global int for storage

void OnCollisionEnter(Collision other)
{
    touchCount++;
}

void OnCollisionExit(Collision other)
{
   touchCount--;
}