Skip to content

Instantly share code, notes, and snippets.

@marcteys
Created March 28, 2015 17:29
Show Gist options
  • Save marcteys/21cfbb28e9dabc9e24f0 to your computer and use it in GitHub Desktop.
Save marcteys/21cfbb28e9dabc9e24f0 to your computer and use it in GitHub Desktop.
Prevent Click on ScrollRect
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
public class PreventClickOnDrag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {
private ScrollRect sr;
private CanvasGroup cg;
void Awake()
{
sr = this.GetComponent<ScrollRect>();
cg = this.GetComponent<CanvasGroup>();
}
public void OnBeginDrag(PointerEventData data)
{
cg.interactable = false;
}
public void OnDrag(PointerEventData data)
{
}
public void OnEndDrag(PointerEventData data)
{
cg.interactable = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment