CodeCamper
CodeCamper

Reputation: 6980

Unity 5 Prevent Scroll Rect From Moving With Mouse

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?

Upvotes: 1

Views: 4557

Answers (2)

Uri Popov
Uri Popov

Reputation: 2167

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

Upvotes: 2

slumtrimpet
slumtrimpet

Reputation: 3267

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) { }
}

Upvotes: 8

Related Questions