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

总结

感谢大家的支持!

相关推荐
玖玥拾5 小时前
Unity3D RPG 入门项目(十一)主角完整战斗、怪物自动刷新、四大类型技能系统
游戏·3d·unity·游戏引擎
Behaviour7 小时前
Unity AI 生态横评对比:官方 AI Beta / Unity CLI / 团结 Codely / 社区 MCP 四大阵营选型
人工智能·unity·ai·游戏引擎·aigc·ai编程
Madokaly17 小时前
基类 DG.Tweening.Tween的源码解读
unity
兰亭妙微UI设计公司18 小时前
兰亭妙微B端界面设计分享:Vantary海事无人系统任务平台UI/UX设计解析
ui·ux
Behaviour19 小时前
Unity游戏之Jenkins的安装部署应用
游戏·unity·jenkins
伊玛目的门徒19 小时前
deepseek harness DSH 安装皮肤脚手架(dsh‑client‑ui‑skin‑center)踩坑完整记录
ui·插件·皮肤·harness·dsh
大Mod_abfun20 小时前
Unity案例10-水晶矿石碰撞碎裂案例
unity·游戏引擎
xcLeigh21 小时前
Unity基础:Input输入系统入门——键盘、鼠标与触摸检测
unity·计算机外设·游戏引擎
zhchyun20082 天前
【Unity UI 进阶】仿 Element UI 打造企业级 Unity UI 组件库(05)
ui·unity·游戏引擎