UGUI—UIDrag

作者:追风剑情 发布于:2024-3-25 13:27 分类:Unity3d

拖动UI界面。

using UnityEngine;
using UnityEngine.EventSystems;
/// <summary>
/// 拖动UGUI
/// </summary>
public class UIDrag : MonoBehaviour, IDragHandler
{
    public Canvas canvas;
    public RectTransform target;

    public void OnDrag(PointerEventData eventData)
    {
        Vector2 delta =  eventData.delta / canvas.scaleFactor;
        target.anchoredPosition += delta;
    }
}

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号