At present working on 2D game. I have main character in which I have attached box collider and circle collider with rigid body component.
I want to handle collision for box collider and circle collider differently.
But at present I can’t able to find any way in which part of main character other obstacles are collided.
How to detect collider type in which collision happen?
You can detect which collider of player has collided with the object from the collision script on the object with which player is collided.
The psuedo code is:
void OnCollisionEnter(Collision2D col) {
if(col.gameObject.name == "player" && col.collider == "box") {
// Do something for box collider
}
else if(col.gameObject.name == "player" && col.collider == "circle") {
// Do something for circle collider
}
}
You have to attach this script to the object with which the player is colliding