Version: 2018.2
public GameObject pointerDrag ;

説明

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); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961