1

How do I prevent the Scroll Rect from moving with the mouse say for example I only want a scroll bar to move it and not by dragging across the image or text with the mouse?

2 Answers 2

8

SubClass ScrollRect and override it's drag handlers?

Untested but should work:

public class NoDragScrollRect : ScrollRect {
  public override void OnBeginDrag(PointerEventData eventData) { }
  public override void OnDrag(PointerEventData eventData) { }
  public override void OnEndDrag(PointerEventData eventData) { }
}
0
2

A simpler solution would be to add a canvas group to the scrollable RectTransform and set it to not block raycast. That way no drag will happen on the RectTransform. This of course only works if you dont need the RectTransform to be interactable at all, otherwise the other answer will do the trick

1
  • Using a CanvasGroup to !BlocksRaycasts works just fine. Setting a ScrollRect to !Interactable, however, does not. Commented Aug 16, 2015 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.