Hey Guys,
I’m having a script on a GameObject with an OnMouseDown() function. The GameObject consists three parts. A base, a body and a head. The body and the head are Child Objects of the GameObject the script sits on. If i now use the OnMouseDown() function, it will not do anything, unless i click the base, i.e. the GameObject that is not a Child. So what i want is no matter what part of my GameObject I’m clicking, the OnMouseDown() should do what it has to do. I was looking for help but nothing came close to my problem. I just don’t know how to include the child GameObjects in my OnMouseDown() function.
Any help appreciated
You cannot directly include the child transforms into OnMouseDown() because it only checks the colliders associated with its own transform.
A convoluted way of doing what you want is to define areas on your collider at runtime and link each area to each part.
In your case it would be alot easier to just have a OnMouseDown() on each child that then calls a function on your parent object.
like this:
public enum parts {
base, head, body
}
on each child:
public class ClickObject : MonoBehaviour {
public parts part;
void OnMouseDown () {
transform.parent.GetComponent<ParentObject>().ClickFuntion(part);
}
}
on parent:
public class ParentObject : MonoBehaviour {
public void ClickFuntion (parts part) {
switch (part) {
case parts.base:
//What should happen when you click base
break;
case parts.head:
//What should happen when you click head
break;
case parts.body:
//What should happen when you click body
break;
}
}
}
Many thanks for your answer 
I will try it as soon as I can.