how check if ScrollRect.OnDrag is active like boolean?

944 Views Asked by At

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 ....."

1

There are 1 best solutions below

0
derHugo On

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) // ....