0

I'm trying to access my scrollrect, to know whether or not the component's drag is used, but the on-drag method is a function as the documentation says, some idea of ​​how to access ondrag like:

"if ondrag is active ....."

  • Possible duplicate of [Detect if a method was overridden using Reflection (C#)](https://stackoverflow.com/questions/2932421/detect-if-a-method-was-overridden-using-reflection-c) – Ruzihm Oct 17 '18 at 16:23
  • @Ruzihm what do you mean? – derHugo Oct 17 '18 at 16:42
  • @derHugo Asker wants to know if their ScrollRect has its OnDrag method overridden. – Ruzihm Oct 17 '18 at 16:46
  • @Ruzihm as I understand it I'ld say asker wants to know whether the ScrollRect is currently being dragged by the user – derHugo Oct 17 '18 at 16:56
  • @derHugo I read it as "How do I know if this `ScrollRect` does anything when dragged?" Asker should clarify their question. – Ruzihm Oct 17 '18 at 16:59
  • 1
    @Ruzihm sure the question is not very clear but from "if ondrag is active" for me it clearly sounds like he wants to know whether or not the Rect is currently being dragged at a certain moment. But maybe we'll have to wait for his position on that ;) – derHugo Oct 17 '18 at 17:01

1 Answers1

1

See ScrollRect.OnBeginDrag and ScrollRect.OnEndDrag

You can simply use the interfaces IBeginDragHandler and IEndDragHandler on your own component and e.g. set a bool there

public class YourComponent : MonoBehaviour, IBeginDragHandler, IEndDragHandler
{
    public bool isDrag { get; private set; }

    public void OnBeginDrag()
    {
        isDrag = true;
    }

    public void OnEndDrag()
    {
        isDrag = false;
    }
}

and than check this bool instead

if(GetComponent<YourComponent>.isDrag) // ....
derHugo
  • 83,094
  • 9
  • 75
  • 115