How can I use a Raycast to tell when a child game object has been mouse clicked

My issue is the parent object has two child objects, so whenever I click any child object, it is recognized twice. How can I get the mouse click to recognize only the child game object that is clicked and not both? Note that the parent object was made with an empty script. Please check the code below:

void Update() {
    if (Input.GetMouseButtonDown(0)) {
        Debug.Log("Pressed left click, casting ray.");
        CastRay();
    }
}

void CastRay() {
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    RaycastHit hit;
    if (Physics.Raycast(ray, out hit, 100)) {
        Debug.DrawLine(ray.origin, hit.point);
    }
}

can someone please help me

What do you mean by “recognized twice”?

There is no checking to see which GameObject was hit. If the OP script was put on every GameObject in the scene, then every GameObject would perform a raycast and every script would fire the Debug because it hit something.

@nowletsstart . The trick is to move the code off the GameObjects being clicked, and onto a single InputHandler GameObject. That way you only do one raycast. That said Unity already has a built in EventSystem complete with various raycasters and interfaces that will do this for you automatically.