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上测试即可

总结

感谢大家的支持!

相关推荐
wtsolutions11 小时前
Understanding Excel Data Formats - What Excel to JSON Supports
ui·json·excel
WinstonJQ12 小时前
AirSim无人机仿真入门(一):实现无人机的起飞与降落
python·机器人·游戏引擎·ue4·无人机
da_vinci_x13 小时前
图标量产:从“手绘地狱”到“风格克隆”?Style Reference 的工业化实战
前端·游戏·ui·prompt·aigc·设计师·游戏美术
wtsolutions15 小时前
Using the Excel to JSON API - Programmatic Access for Developers
ui·json·xhtml
Jet_5816 小时前
神庙逃亡(Temple Run)IL2CPP 逆向实战:从 APK 到 Frida 实现角色无敌
unity·il2cpp·逆向工程·frida·android逆向·hook技术·游戏逆向
weixin_402486341 天前
在adobe illustrator 上写latex code 显示数学公式 安装 LaTeX2Illustrator
ui·adobe·illustrator
Dr.勿忘1 天前
MUMU模拟器adb连接失败:cannot connect to 127.0.0.1:16384: 由于目标计算机积极拒绝,无法连接。 (10061)
游戏·unity·adb·游戏程序·调试·模拟器
垂葛酒肝汤2 天前
Unity中的协程的原理
unity·游戏引擎
航Hang*2 天前
Photoshop 图形与图像处理技术——第9章:实践训练2——变换花朵颜色与绘制正方体
图像处理·笔记·学习·ui·photoshop·期末·复习