How do I use OnMouseDown() for a child object?

I would like code to run when I click on the child object. However, it never triggers the OnMouseDown() in the child class, even if the parent object is in an ignore raycast layer.

if there’s something in the way it will never get triggered.
debug first to find out what your ray is hitting and go from there.

just add a debug log with the hit objects name to every mouse click to test it

OnMouseDown() looks for a collider on the object with the script. That script would have to be on the child and the child would have to have a collider. I’m assuming your script is located on the parent.

You could use something like this from the parent during Update:

if(Input.GetMouseButtonDown(0))
		{
			RaycastHit hit;
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			if (Physics.Raycast(ray, out hit))
			{ 
				if( hit.collider == myGameObject.GetComponent<Collider>())
				{
					//do this
				{
			{ 
		{