- Home /
differentiate between box collider of two different Game Objects in UNITY
Hi. I have two GameObjects
Body1 and Body2, Both have separate BoxCollider
. i want to identify which GameObject
(Body1 or Body2) have hit the other.
Answer by CalleRC · Jul 29, 2017 at 11:17 AM
@JaZZi I'm not quite sure what you mean, but maybe this will help :D
You can give your different objects different tags, and then check if the tags on the collided object is equal to the objects tag. To give an object a tag, you need to create it under edit/project settings/tags and layers, and then apply the tag under the inspector.
void OnCollisionEnter(Collision other) {
if(other.transform.tag == "Body2")
//then do something
}
You can also choose which objects that can collide with eachother under edit/project settings/physics and then change the "layer collision matrix". To insert objects into the matrix, you need to create a new layer, under edit/project settings/tags and layers, and then apply the new layer to the object under the inspector.
Your answer
![](https://koobas.hobune.stream/wayback/20220612131445im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to detect collision with character controller on box collider 0 Answers
Finding number of bowling pins knocked over 1 Answer
Box Collider on Spring Joint Randomly Stops Working in Editor and Builds 1 Answer
How to make a progress bar go up after two objects collide? 0 Answers
BoxCollider get stuck when dragging over the border of two BoxColliders 1 Answer