I bet there are better solutions, but the first thing that comes to my mind is that:
Check if you are clicking an UI element, bevor moving your object on mouse up event.
You can check if you hit an UI element by using a GraphicsRaycaster
to cast a ray on your mouse position. If it hits anything, then you are clicking on any canvas.
See: https://docs.unity3d.com/Manual/script-GraphicRaycaster.html