Drag a gameObject only on a plane

Hi everybody.

I have the gameobject like the one in the image I have uploaded and what I want to do is to drag the sphere(the one inside the red circle) into the rest of the gameobject.

I am using it with Vuforia, so the problem that I have is that if I move the camera, the sphere move together with the camera and it’s not anymore aligned with the rest of the gameobject.

This is the code that I am using for the drag.

private float dist;
   private Vector3 v3Offset;
    private Plane plane;
    public GameObject mainStructure;

    void OnMouseDown()
    {
    
        plane.SetNormalAndPosition(mainStructure.transform.up, mainStructure.transform.position);
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);    
        float dist;
        plane.Raycast(ray, out dist);
        v3Offset = transform.position - ray.GetPoint(dist);
    }

    void OnMouseDrag()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        float dist;
        plane.Raycast(ray, out dist);  
        Vector3 v3Pos = ray.GetPoint(dist);  
        Vector3 lastPos = v3Pos + v3Offset;    
        transform.position = plane.ClosestPointOnPlane(lastPos);
    }

What I get with this code that the sphere will go back to the same plane once I hit about the mouse.

I hope I explained my problem right.

Thanks for your attention.

5688763--593869--gameobject.png

                private void OnMouseDrag()
                {

                var dragPlane = new Plane(dragPlaneTransform.up, dragPlaneTransform.position);
                Ray ray = playerCamera.ScreenPointToRay(Input.mousePosition);
                float enter;

                if (dragPlane.Raycast(ray, out enter))
                {
                    //Get the point that is clicked
                    Vector3 hitPoint = ray.GetPoint(enter);

                    //Move your cube GameObject to the point where you clicked
                    transform.position = hitPoint;
                }