Camera won't follow a selected object

When I click on an object that has a PolygonCollider2D the camera snaps to the objects position but doesn’t continue to follow the object (the object is moving), like I want. Why?

    void FixedUpdate()
    {
        followTargetOnClick();
    }

    private void followTargetOnClick()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector2 camPos = new Vector2((cam.position).x, (cam.position).y);
            Vector2 mousePos = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
            RaycastHit2D hit = Physics2D.Raycast(mousePos, camPos, 0.5f);
            if (hit.collider != null)
            {
                if (hit.collider.GetComponent<PolygonCollider2D>())
                {
                    isSelected = true;
                    if(isSelected == true)
                    {
                        setPos(hit.transform.position.x, hit.transform.position.y);
                    }
                }
            }
        }
    }

    public void setPos(float x, float y) //sets cam's position
    {
        cam.position = new Vector3(x, y, -1);
    }

It seems you are only setting the position on frames that the mouse is clicked.
Try adding a new private Transform variable “target” and changing the line setPos(hit.transform... etc to target = hit.transform;.

Then outside of the if statement for Input.GetMouseButtonDown(0)) (after the statement but still inside void followTargetOnClick()) add the line setPos(target.position.x, target.position.y);

This should update the position of the camera every fixedUpdate but update the targeted Transform only when the mouse button is pressed.