Unity自定义区域UI滑动事件

自定义区域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上测试即可

总结

感谢大家的支持!

相关推荐
三巧1 小时前
Godot 敌人生成半径和围墙不匹配,导致敌人错误的生成在围墙外的解决代码
游戏引擎·godot
技术小甜甜1 小时前
【Godot引擎】如何使用内置的全局搜索功能提升开发效率
游戏引擎·godot
技术小甜甜1 小时前
【Godot】如何导出 Release 版本的安卓项目
android·游戏引擎·godot
pop_xiaoli4 小时前
UI学习—cell的复用和自定义cell
学习·ui·ios
XR-AI-JK10 小时前
Unity VR/MR开发-VR设备与适用场景分析
unity·vr·mr
ChiLi_Lin10 小时前
Unity异常上报飞书工具
unity·游戏引擎·飞书
Magnum Lehar12 小时前
vulkan游戏引擎的makefile启动环境实现
游戏引擎
地狱为王21 小时前
基于VLC的Unity视频播放器(四)
unity·游戏引擎·音视频
1 天前
Unity与Excel表格交互热更方案
unity·游戏引擎·excel
测试老哥1 天前
Pytest+Selenium UI自动化测试实战实例
自动化测试·软件测试·python·selenium·测试工具·ui·pytest