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

总结

感谢大家的支持!

相关推荐
weixin_424294678 小时前
在Unity中,摄像机移动时出现“残影”或“闪烁”是常见问题,主要原因和处理方法。
unity·游戏引擎
孟无岐8 小时前
【Laya】Browser 使用说明
typescript·游戏引擎·游戏程序·laya
天人合一peng9 小时前
unity 3d 通过游戏对象的名子查到其对象
游戏·unity·游戏引擎
纯属个人爱好10 小时前
Unity2020+PicoNeo3Pro开发
unity·vr
__water13 小时前
RHK《Unity接入DeepSeek问答》
unity·游戏引擎·智能问答·deepseek接入·deepseekapikey
小雨下雨的雨14 小时前
Flutter 框架跨平台鸿蒙开发 —— Center 控件之完美居中之道
flutter·ui·华为·harmonyos·鸿蒙
小小工匠14 小时前
LLM - A2UI:Google 引领的生成式 UI 革命
ui·a2ui
康de哥15 小时前
MCP Unity + Claude Code 配置关键步骤
unity·mcp·claude code
小雨下雨的雨15 小时前
Flutter 框架跨平台鸿蒙开发 —— Placeholder 控件之布局雏形美学
flutter·ui·华为·harmonyos·鸿蒙系统
美团骑手阿豪15 小时前
Unity3D大规模点击检测:GPU Picking vs MeshCollider + Raycast
unity