unity UGUI 拖拽ui跟随手指或鼠标移动

using UnityEngine;
using UnityEngine.EventSystems;

public class ItemButton : MonoBehaviour, IDragHandler, 

 private RectTransform curRecTran;

 private void Awake()
    {      
        curRecTran = transform.GetComponent<RectTransform>();
    }

 public void OnDrag(PointerEventData eventData)

    {    
        Vector3 globalMousePos;

if(RectTransformUtility.ScreenPointToWorldPointInRectangle(curRecTran,eventData.position,

eventData.pressEventCamera, out globalMousePos))

        {
            curRecTran.position = globalMousePos;
        }

    }

}

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页