Version: 2018.4
LanguageEnglish
  • C#

PointerEventData.pointerDrag

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public GameObject pointerDrag;

Description

The object that is receiving OnDrag.

Calling pointerDrag returns the GameObject this script is attached to. This is a ScrollView.

The parent of the pointerDrag can be set to null. This prevents OnDrag and OnEndDrag from being called.

// OnDrag() has the pointerDrag GameObject removed.
// This stops the cursor being moved.

using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI;

public class ExampleScript : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler { private float timeCount;

public void OnBeginDrag(PointerEventData data) { Debug.Log("OnBeginDrag: " + data.position); data.pointerDrag = null; }

public void OnDrag(PointerEventData data) { if (data.dragging) { timeCount += Time.deltaTime; if (timeCount > 1.0f) { Debug.Log("Dragging:" + data.position); timeCount = 0.0f; } } }

public void OnEndDrag(PointerEventData data) { Debug.Log("OnEndDrag: " + data.position); } }