【问题标题】:drag and drop in unity, drag behind other UI elements统一拖拽,拖到其他UI元素后面
【发布时间】:2017-07-30 23:32:45
【问题描述】:

我有一个带有Grid Layout Group 组件的面板。在里面我有一个名为 slot 的面板,上面有一个背景图像,在里面我有一个包含 2 个图像的预制件。它看起来像这样: 我写了一个拖放脚本,在TankPrefab

public class DragHandler : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {
    public static GameObject itemBeingDragged;
    Vector3 startPosition;
    public void OnBeginDrag(PointerEventData eventData)
    {
        itemBeingDragged = gameObject;
        startPosition = transform.position;
    }
    public void OnDrag(PointerEventData eventData)
    {
        transform.position = Input.mousePosition;   
    }
    public void OnEndDrag(PointerEventData eventData)
    {
        itemBeingDragged = null;
        transform.position = startPosition;
    }
}

当我将坦克拖过坦克插槽之后的插槽时,我遇到了问题。它把坦克拉到他身后: 我在OnBeginDrag 中尝试了transform.SetAsLastSibling();,但它只是将它移动到父级(插槽)的第一个并且我希望它高于其他插槽所以我也尝试了transform.parent.SetAsLastSibling();,起初它看起来像它正在工作,但在 2 次拖动后,坦克消失了

【问题讨论】:

    标签: c# user-interface unity3d


    【解决方案1】:

    尝试将“画布”组件添加到您的预制件中并选中“覆盖排序”并设置排序顺序。我想我还必须添加一个图形光线投射器。

    检查员:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多