Is there a way to ensure a cursor position must hover over an object to work in OnMouseDrag?

I never really know how to word these questions, because there’s always more questions than one.

Essentially, I have an object I move up and down using this code:

    private Vector3 offset;
    private bool stopDrag = false;
    private bool twoClicks;
    //private int fingerCount;

    void Start()
    {
        Input.multiTouchEnabled = false;
    }

    void Update()
    {
        if (Input.touchCount > 1)
        {
            stopDrag = true;
        }

        //if (fingerCount > 0)
            //print("User has " + fingerCount + " finger(s) touching the screen");

    }

    /***Slider***/
    void OnMouseDown(){

        stopDrag = false;
        //screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
        offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(1, Input.mousePosition.y));
    }

	void OnMouseDrag(){

        /*int fingerCount = 0;
        foreach (Touch touch in Input.touches)
        {
            if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
                fingerCount++;

        }*/
        if (Input.touchCount == 1 && stopDrag == false)
        {
            Vector3 cursorPoint = new Vector3(1, Input.mousePosition.y);
            Vector3 cursorPosition = Camera.main.ScreenToWorldPoint(cursorPoint) + offset;
            transform.position = cursorPosition;

            /***Lock down slider***/
            Vector3 pos = transform.position;
            pos.y = Mathf.Clamp(pos.y, -4, 4);
            transform.position = pos;
        }
        if (stopDrag == true)
        {
            return;
        }
	}

So I’m able to move the object up and down where the cursor position is, but if I do a second touch (say to press a button) and then take my finger off the object with the second touch held down, the object will jump to the cursor position (within the ‘clamped’ Y axis).

Does anyone know of a way to stop that from happening? I’ve tried adding a bool that turns true when more than one touch is detected, but I also want to be able to move the object while I’m making another touch on something else. I guess I want to have my cake and eat it too. Meaning, it’s either one or the other as far as I’m aware.

All I can think of is to make it so the OnMouseDrag can only work if the cursor is hovering over the object, but I’m not sure how I’d achieve that.

Ignore this. Made an edit below*I fixed the issue I was having by adding this code to the script:

    void OnMouseOver()
    {
        if (GameObject.FindWithTag("Player"))
        {
            stopDrag = false;
        }
    }

    void OnMouseExit()
    {
        stopDrag = true;
    }

I can now have my cake and eat it too! Hurrah. I always end up fixing the problem before anyone can help me. But hopefully this helps anyone else with any problems/bugs they’ve encountered when it comes to dragging an object.
Input.touchCount has been very helpful.

*Edit: Actually, it’s not what I want. Because you can still jump the object’s position like before, you’re just confined to the game object’s hover space. Also, it’s easier to lose the drag of the object because when you drag your finger away from the object the dragging stops.

I guess what I really want is to be able to click and drag the object anywhere on the screen, but to also stop it from jumping to the cursor’s position when I touch somewhere else and lift off the first touch.