Unity3D UI, calculation for position dragging an item?

后端 未结 3 1867
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 14:01

These days it\'s incredibly easy to drag UI elements in Unity: Make a few UI items. Add Component -> Event -> Event Trigger. Drop on the script below. Click

3条回答
  •  清酒与你
    2020-11-28 14:10

    For Draging stuff I just do this :

    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;
    
    public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {
    
    
    
        public void OnBeginDrag(PointerEventData eventData) {
    
        }
    
        public void OnDrag(PointerEventData eventData) {
            //Debug.Log ("OnDrag");
    
            this.transform.position = eventData.position;
    
            }
    
        public void OnEndDrag(PointerEventData eventData) {
            Debug.Log ("OnEndDrag");
    
        }
    }
    

提交回复
热议问题