How to detect which collider is clicked in 3D

I wanna make point & click game and I want to add movement by clicking on object, but to do this I need make 2 colliders for object and I wanna detect which collider is clicked.

Version: 2021.3.14f1

I found solution, here code:

private void OnMouseDown()
{
    if (Input.GetMouseButtonDown(0))
    {
        RaycastHit hit;
        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
        {
            if (hit.collider == GetComponents<Collider>()[0])
                // On first collider
            else if (hit.collider == GetComponents<Collider>()[1])
                // On second collider
             // More `else if` if you have more colliders
        }
    }
}

But you need to remember what index for each colliders

Just a suggestion: It would be cheaper on overhead if you stored a reference to your colliders on Start rather than running two or more GetComponents every time you click.

    Collider collider0;
    Collider collider1;

    private void Start ()
    {
        collider0 = GetComponents<Collider>()[0];
        collider1 = GetComponents<Collider>()[1];
    }

    private void OnMouseDown()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
            {
                if (hit.collider == collider0)
                    // On first collider
                else if (hit.collider == collider1)
                    // On second collider
                 // More `else if` if you have more colliders
            }
        }
    }

This solution is better if each collider will be used multiple times