【发布时间】:2016-04-15 01:30:42
【问题描述】:
我正在 Unity 中创建一个库存系统,但我一直被一个棘手的谜团所迷惑。当我将库存系统中的项目拖回之前的插槽时,OnMouseEnter 函数无法执行。我使用 Control Double 键盘快捷键创建了三个插槽。它们被命名为“Slot”、“Slot(1)”和“Slot2”。 当我将我的项目拖到 Slot(1) 时,我无法将它拖回第一个插槽“Slot”。当我将我的项目拖到 Slot(2) 时,我无法将它拖到我的第二个插槽“Slot(1)”。 我注意到当我尝试时不会调用 OnPointerEnter() 方法将项目从“Slot(2)”拖到“Slot(1)”或“Slot”。这是为什么呢?
这个库存移动脚本应该通过将项目的父项设置为鼠标拖动到的插槽,然后将其定位到本地位置的 Vector3.Zero。 InventoryController脚本附加到UIImage,inventory,SlotController脚本附加到UIImage,Slot,Item脚本附加到UIImage强>,项目。我的层次结构、检查器和脚本如下图所示。感谢您帮助我进阶!
【问题讨论】:
-
我认为只有在您选择了一个项目时才应该开始拖动 (
OnBeginDrag)。不要简单地设置controller.dragging = true。此外,您不需要SlotController中的布尔值。只需直接访问controller.dragging。使用 update 来检查 bool 可能会导致在OnPointerEnter中检查时 bool 没有更新的问题。
标签: c# user-interface debugging unity3d unity5