Reputation: 617
How can I identify a collision between two different BoxCollider2D objects in Unity in the OnCollisionEnter,Exit, and Stay Methods using Collision2D in C#. Thanks
Upvotes: 0
Views: 1543
Reputation: 11302
When I have multiple colliders that should trigger different actions I place them in different game object children.
For example, if I have one character (game object) with two different colliders, one for the head and another one for the rest of the body, that trigger different actions I create two game object inside the character. Then each child will have its script containing OnCollision
methods.
You can also name each game object (head and body) or change their tag and then you can identify the colliders using this.gameObject.name
or this.gameObject.tag
since this will be running in different game objects.
I think this makes game logic simple instead of handling multiple actions inside the same game object collision functions and it has been working good for me so far.
Upvotes: 1