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

总结

感谢大家的支持!

相关推荐
脩衜者11 小时前
极其灵活且敏捷的WPF组态控件ConPipe 2026
前端·物联网·ui·wpf
TO_ZRG11 小时前
Unity打包安卓、iOS知识点
android·unity·android studio
冰凌糕11 小时前
Unity3D Shader 顶点动画 呼吸和水波
unity
呆呆敲代码的小Y12 小时前
【Unity 实用工具篇】| UX Tool 工具 快速上手使用,提高日常开发效率
游戏·unity·游戏引擎·游戏程序·ux
世洋Blog13 小时前
Unity开发微信小程序-避开新InputSystem有关坑
unity·微信小程序
小笔学长13 小时前
React 入门:构建交互式 UI 的基础
ui·项目实战·前端开发·react框架·jsx语法
zhaocarbon13 小时前
VUE 4向云台 8向云台UI
css·vue.js·ui
阿蔹13 小时前
UI测试自动化-Web-Python-Appium
前端·python·ui·appium·自动化
lifewange1 天前
UI自动化页面元素定位有几种方式
前端·ui·自动化
简简单单OnlineZuozuo1 天前
提示架构:设计可靠、确定性的AI系统
人工智能·unity·架构·游戏引擎·基准测试·the stanford ai·儿童