Check out example codes for "drag object unity 2d". It will help you in understanding the concepts better.

Code Example 1

public class followMouse : MonoBehaviour
{

    bool canDrag = false;

    Vector3 itemPos;
    void Update()
    {
        transform.position = Input.mousePosition;
        if (!Input.GetMouseButton(0))
        {
            canDrag = false;
        }

    }
    
    void OnTriggerStay2D(Collider2D other)
    {
        if (other.CompareTag("itemIcon"))
        {
            if (Input.GetMouseButton(0))
            {
                canDrag = true;
                other.transform.position = Input.mousePosition;
            }
            
        }
    }



}

Code Example 2

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DragAndDrop : MonoBehaviour
{

    private bool isDragging;

    public void OnMouseDown()
    {
        isDragging = true;
    }

    public void OnMouseUp()
    {
        isDragging = false;
    }

    void Update()
    {
        if (isDragging) {
            Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
            transform.Translate(mousePosition);
        }
    }
}

Learn ReactJs, React Native from akashmittal.com