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

总结

感谢大家的支持!

相关推荐
踏过山河,踏过海6 小时前
【用ui文件做个简单工具的开发,为什么修改完ui后,程序重新编译运行后,GUI界面还是不变呢?】
qt·ui
June bug9 小时前
【领域知识】休闲游戏一次发版全流程:Google Play + Apple App Store
unity
John_ToDebug9 小时前
WebContent 与 WebView:深入解析浏览器渲染架构的双层设计
c++·chrome·ui
星夜泊客12 小时前
C# 基础:为什么类可以在静态方法中创建自己的实例?
开发语言·经验分享·笔记·unity·c#·游戏引擎
小小测试开发12 小时前
UI自动化测试:CSS定位方式超详细解析(附实战示例)
css·ui·tensorflow
dzj202112 小时前
PointerEnter、PointerExit、PointerDown、PointerUp——鼠标点击物体,则开始旋转,鼠标离开或者松开物体,则停止旋转
unity·pointerdown·pointerup
心前阳光13 小时前
Unity 模拟父子关系
android·unity·游戏引擎
光影少年14 小时前
智能体UI ux pro max
前端·ui·ux
在路上看风景16 小时前
26. Mipmap
unity
一叶星殇17 小时前
WPF UI 框架大全(2026版)
ui·wpf