标签:
创建两个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); } }
代码很简单这里不再赘述
运行效果
Unity5_UGUI_基础知识7_Drag面板切换前后Index
标签:
原文地址:http://www.cnblogs.com/xmcrew/p/4496542.html