创建两个Panel分别为PanelA,PanelB,修改一下文字和B的颜色以便区分开来
如图
给两个Panel分别添加DragAndSelectIndex.cs
具体代码如下
using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.EventSystems; public class DragAndSelectIndex : MonoBehaviour, IPointerDownHandler, IDragHandler { public void OnPointerDown (PointerEventData data) { this.transform.SetSiblingIndex(1); } public void OnDrag(PointerEventData eventData) { this.transform.SetSiblingIndex(0); transform.position=Input.mousePosition; } public void OnPointerUp(PointerEventData eventData) { this.transform.SetSiblingIndex(0); } }
代码很简单这里不再赘述
运行效果
时间: 2024-10-22 20:12:53