我正在研究库存系统,目前我正在考虑交换库存点.目前我有一个层次结构:
现在我注意到的是,当我交换它时,只有当我用库存插槽4交换说库存插槽1时才能工作.但是如果我要将库存插槽4替换为库存插槽1我的OnPointerEnter和OnPointerExit不注册,这应该是对的吗?这似乎是一个层次结构问题,我不知道如何解决这个问题.
交换的GIF和我的库存插槽游戏对象的屏幕截图:
http://imgur.com/kS1C1TL – GIF
我的OnPointers for Inventory_Slot脚本的代码:
public static GameObject itemBeingDragged;
public static GameObject itemCurrentlyOn;
public void OnPointerEnter(PointerEventData data){
itemCurrentlyOn = gameObject;
}
public void OnPointerExit(PointerEventData data){
itemCurrentlyOn = null;
}
public void OnPointerUp(PointerEventData data){
// IF we are dragging an item.
if(itemBeingDragged != null){
print (itemCurrentlyOn);
// IF we release the mouse button on an actual inventory slot.
if(itemCurrentlyOn != null && itemCurrentlyOn != gameObject){
// Swap the information in the 2 inventory slots.
GetComponentInParent<Inventory> ().SwapInventorySlots (itemBeingDragged.GetComponent<Inventory_Slot> (), itemCurrentlyOn.GetComponent<Inventory_Slot> ());
}
itemBeingDragged = null;
// return this gameobject to its original location.
rectTrans.localPosition = localRectTrans;
}
}
public void OnBeginDrag(PointerEventData data){
// IF we have an item to drag.
if(isItem){
// Set the itemBeingDragged to this gameobject.
itemBeingDragged = gameObject;
// Set the current item we are hovered on to null.
//itemCurrentlyOn = null;
}
}
此外,如果我要将库存插槽5移到层次结构中的库存插槽1之上,那么如果有意义的话我可以向后交换.我会发布一个GIF来制作更好的视觉效果:
新层次结构:
http://imgur.com/rjueuYK – GIF
我是如何进行库存不良操作的,或者我是否可以在Unity中使用某个游戏对象修复此层次结构问题?
解决方法:
可能是因为您可能没有清空项目所在的原始插槽而导致此错误.这可能不是您要查找的确切答案,但在本教程中,与您所面临的问题类似的问题是解释.
https://www.youtube.com/watch?v=1gveNfidKPA&t=17m5s
希望这可以帮助.
原文地址:https://codeday.me/bug/20190706/1395418.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。