This code works but it has a little delay on computer controls and higher delay on mobile touch screen controls, so its not responsive as I want it to be.
void OnMouseDown()
{
offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, transform.position.y, 0.0f));
}
void OnMouseDrag()
{
Vector3 newPosition = new Vector3(Input.mousePosition.x, transform.position.y, 0.0f);
transform.position = Camera.main.ScreenToWorldPoint(newPosition) + offset;
transform.position = new Vector2(Mathf.Clamp(transform.position.x, posXMin, posXMax), transform.position.y);
}