moving objects back and fourth between to points and stopping it on mouse click

Currently trying to move a sprite between two points and making it stop between those two points on mouseclick/tap. Cant figure out how to do that (Script isnt laying on the object that is being moved btw)

void Update() {
        if(isMoving){
        Vector3 v = startingPos;
        v.x += distanceToCover * Mathf.Sin(Time.time * triangleSpeed);
        transform.position = v;
        }
        if(Input.GetMouseButtonDown(1)){
            
        }
        
    }

if (Input.GetMouseButtonDown(1)) {
isMoving = false;
}
else
{
isMoving = true;
}

Should work.