using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class TuoZhuaiYiDong : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
{
public Vector3 yuanshiweizhi ;
public void OnDrag(PointerEventData eventData)
{
SetDraggedPosition(eventData);
}
public void OnBeginDrag(PointerEventData eventData)
{
yuanshiweizhi = transform.position;
SetDraggedPosition(eventData);
}
public void OnEndDrag(PointerEventData eventData)
{
transform.position = yuanshiweizhi;
}
private void SetDraggedPosition(PointerEventData eventData)
{
var rt = gameObject.GetComponent<RectTransform>();
Vector3 globalMousePos;
if (RectTransformUtility.ScreenPointToWorldPointInRectangle(rt, eventData.position, eventData.pressEventCamera, out globalMousePos))
{
rt.position = globalMousePos;
}
}
}
|