Need to prevent Click triggered when scrolling
I have a Scroll List with EventTrigger elements. Scroll works thanks to Scroll fix script (found somewhere; see below).
The problem appears on phones:
When I scroll and my start and end finger position remains at the same element (short scroll) the following happens: the list is scrolled and the Pointer Click event is triggered (which I didn't want)
Same happens with dragging. I touch the screen, start dragging up and down. It makes the list move(scroll) but if my finger ends at the same element as the first touch It fires the Click.
So I need to make it work properly. Clicks have to be triggered on clicks only and has to be prevented when the list is scrolled or dragged.
Thank you for any suggestions.
Here's the scroll fix script that I use:
public class ScrollFix: MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IScrollHandler, IDropHandler
{
public ScrollRect MainScroll;
public void OnBeginDrag(PointerEventData eventData)
{
MainScroll.OnBeginDrag(eventData);
}
public void OnDrag(PointerEventData eventData)
{
MainScroll.OnDrag(eventData);
}
public void OnEndDrag(PointerEventData eventData)
{
MainScroll.OnEndDrag(eventData);
}
public void OnScroll(PointerEventData data)
{
MainScroll.OnScroll(data);
}
}
Answer by yoshomitsu · Jan 23, 2018 at 11:42 PM
Well, the solution is quite easy, but I just have lack of experience :\
So this is the solution that worked for me:
public void OnPointerClick (PointerEventData eventData)
{
if (eventData.IsScrolling () || eventData.dragging)
{
}
else
MyFunction ();
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612150901im_/https://answers.unity.com/themes/thub/images/avi.jpg)