using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class Tool : MonoBehaviour, IDragHandler,IPointerDownHandler,IPointerUpHandler{
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OnPointerDown(PointerEventData eventDate) {
Debug.Log ("start");
}
public void OnDrag (PointerEventData eventData) {
GameObject pointerDrag = eventData.pointerDrag;
Vector3 globalMousePosition;
if (RectTransformUtility.ScreenPointToWorldPointInRectangle(pointerDrag.GetComponent<RectTransform>(), eventData.position, Camera.main, out globalMousePosition))
{
pointerDrag.transform.position = globalMousePosition;
}
}
public void OnPointerUp(PointerEventData eventData) {
Debug.Log ("end");
}
}
Unity 拖动UI物体
最新推荐文章于 2024-08-02 16:38:07 发布