Don't update the mouse position if click on an UI object unity

Hello everyone,
I am creating a 2D Space strategy game. When player click on a position, a waypoint created on that position and then player ships move to that position. But when I am click on an UI object, waypoint position must not be updated. How to achieve this?
7440992--912161--ss2d.JPG

My current code:

void Update ()
    {
        if (Input.GetMouseButtonDown(0))
        {
            carrierTarget = cam.ScreenToWorldPoint(Input.mousePosition);
            carrierTarget.z = transform.position.z;
            waypoint.position = carrierTarget;
        }
    }
1 Like

Thank you, it’s working.