How can i grab objects with using OnCollision or Ontrigger?

Hello. I’m making some kind of water volleyball game. When the player touches the ball, the player must pick up the ball. this is a 2D game. I know it’s wrong but these are the codes i use:

public void OnTriggerEnter2D(Collider2D grab)
    {
        if (grab.gameObject.tag == "ball")
        {

            RaycastHit2D hitInfo = Physics2D.Raycast(rayPoint.position, transform.right, rayDistance);

        if (hitInfo.collider != null && hitInfo.collider.gameObject.layer == layerIndex)
            {

                grabbedObject = hitInfo.collider.gameObject;
                grabbedObject.GetComponent<Rigidbody2D>().isKinematic = true;
                gameObject.transform.position = grabPoint.position;
                grabbedObject.transform.SetParent(transform);
            }
            else
            {
                grabbedObject.GetComponent<Rigidbody2D>().isKinematic = false;
                grabbedObject.transform.SetParent(null);
                grabbedObject = null;

            }
            Debug.DrawRay(rayPoint.position, transform.right * rayDistance);
        }