using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; public class DragPanel:MonoBehaviour,IDragHandler,IPointerDownHandler { private RectTransform panel; private Canvas canvas; void Start() { panel = this.GetComponent<RectTransform>(); canvas = GameObject.Find("Canvas").GetComponent<Canvas>(); } public void OnDrag(PointerEventData eventData) { panel.anchoredPosition+=eventData.delta/canvas.scaleFactor; } public void OnPointerDown(PointerEventData eventData) { panel.SetAsLastSibling();//设置最高层 } }
标签:canvas,拖动,void,Unity,UI,eventData,using,public,panel From: https://www.cnblogs.com/KoitoYu/p/17965528