- Home /
Determine which collider was clicked
Hey folks,
short question (I hope) - I have a GameObject with two seperate PolygonColliders attached (for Mouse detection).
In the OnMouseDown method, I want to route to different methods depending on which collider was clicked. But I see no way to find out - any suggestions?
Comment
Best Answer
Answer by fafase · Feb 10, 2015 at 05:11 AM
public enum ColliderPosition{None,Left,Right}
public class ColliderInfo:monoBehaviour{
[SerializeField] private ColliderPosition colPos = ColliderPosition.None;
private Action ActionOnClick = ()=>{};
void Start(){
switch(colPos){
case ColliderPosition.Left:
ActionOnClick = LeftClick;
break;
case ColliderPosition.Right:
ActionOnClick = RightClick;
break;
}
}
void OnMouseDown(){
ActionOnClick();
}
void LeftClick(){}
void RightClick(){}
}
The you just need assign the value in ColliderPosition in inspector
Your answer
![](https://koobas.hobune.stream/wayback/20220613182907im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Internal collisions 1 Answer
How to make collision with moving CharacterController and moving Collider. 1 Answer
How to set a Collider of a GameObject to Inactive similar to the SetActiveMethod 1 Answer
Object wont move after collision with more than one point 1 Answer
How do I show an object falling inside another transparent object? 1 Answer