自定义区域UI滑动事件
介绍
一提到滑动事件联想到有太多的插件了比如EastTouchBundle,今天想单纯通过UI去做一个滑动事件而不是基于Box2d或者Box去做滑动事件。
制作
1.创建一个Image

2.创建脚本
csharp
using UnityEngine;
using UnityEngine.EventSystems;
/// <summary>
/// UI的拖拽事件
/// </summary>
public class ImageDrag : MonoBehaviour,IDragHandler,IBeginDragHandler,IEndDragHandler
{
public void OnBeginDrag(PointerEventData eventData)
{
Debug.LogError("开始拖拽");
}
public void OnDrag(PointerEventData eventData)
{
Debug.LogError("拖拽中");
}
public void OnEndDrag(PointerEventData eventData)
{
Debug.LogError("结束拖拽");
}
}
将脚本放到Image上测试即可
总结
感谢大家的支持!