Search Unity

ScrollRect: how to terminate dragging while mouse is still down

Discussion in 'UGUI & TextMesh Pro' started by nochnoyru, Oct 19, 2018.

  1. nochnoyru

    nochnoyru

    Joined:
    Jul 5, 2018
    Posts:
    4
    Hi! I have vertical list of game units (orcs, humans, buildings, etc) which can be grabbed from the list and dropped to the game field. But when I take some unit and start dragging it outside the ScrollView, for the ScrollView drag-and-drop operation is not over and it contiunes to follow my mouse (which is far away from the list) and scrolling with it. That looks ugly.

    So how do I make ScrollView to stop scrolling, even if mouse button is still down?
    Thanks
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Well, one "brute-force" option would be to set scrollRect.enabled = false, thereby terminating ALL of the scroll rect's functions.

    Are you sure that you want your list of drag-and-drop options to be scrollable by dragging in the first place? That seems kind of weird.
     
  3. nochnoyru

    nochnoyru

    Joined:
    Jul 5, 2018
    Posts:
    4
    Thanks for ansvering, but why it's weird? I make game for touch devices, so all lists have to be scrollable by dragging, not by scrollbars.

    And yes, I considered this option with scrollRect.enabled = false but, list just freezes in its scroll position, but I need it to jump back gracefully to its initial position.

    This is weird that I still cannot find solution to this problem. I am only one who tried to make scrollable lists with drag-n-drop functionality?
     
  4. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    I don't see how that follows. Scrollbars work just fine on touch devices.

    Well, you said you wanted it to stop scrolling. If what you actually wanted was for it to jump back to its original position, you should have said that.

    To do that, you'd need to save the position when the scroll starts so that you'll be able to restore it later.