As title says, i want to check if ScrollRect is currently dragged, but in some easy way, without implementing Drag interfaces, only from Scroll Rect reference if thats possible.
When I change my inspector view from Normal to Debug, there is a bool variable called “Dragging” in Scroll Rect and it shows exactly what I want, but I can’t get its value from code. Is there any way to get its value or some other way to check if Scroll Rect is being dragged?
@Molioo, you can use default Eventsystem callbacks.
- Attach a script to the gameobject to which you have added the Scroll Rect component.
- Inside that script inherit the interfaces named as IBeginDragHandler and IEndDragHandler (can use IDragHandler instead IBeginDragHandler).
- Implement the methods from the interfaces named as OnBeginDrag and OnEndDrag
- Now you have access to that private Dragging flag…well…sort of.
That’s it. Hope this helps.
No, not without using reflection to access internal fields. As you might know large parts of the new UI system is open source. As you can see the m_Dragging bool is a private field of the ScrollRect class. If you want you can build your own UnityEngine.UI version but of course you have to keep it up to date.