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

using UnityEngine;
using UnityEngine.EventSystems;

public class ItemButton : MonoBehaviour, IDragHandler, 

 private RectTransform curRecTran;

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

 public void OnDrag(PointerEventData eventData)

    {    
        Vector3 globalMousePos;

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

eventData.pressEventCamera, out globalMousePos))

        {
            curRecTran.position = globalMousePos;
        }

    }

}

你可能感兴趣的:(UGUI,Unity3D)