加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – OnPointerEnter和OnPointerExit未在Unity 5.3.4中注册

发布时间:2020-12-15 22:31:03 所属栏目:百科 来源:网络整理
导读:我正在研究库存系统,目前我正在考虑交换库存点.目前我有一个层次结构: 现在我注意到的是,当我交换它时,只有当我用库存插槽4交换说库存插槽1时才能工作.但是如果我要将库存插槽4替换为库存插槽1我的OnPointerEnter和OnPointerExit不注册,这应该是对的吗?这
我正在研究库存系统,目前我正在考虑交换库存点.目前我有一个层次结构:

enter image description here

现在我注意到的是,当我交换它时,只有当我用库存插槽4交换说库存插槽1时才能工作.但是如果我要将库存插槽4替换为库存插槽1我的OnPointerEnter和OnPointerExit不注册,这应该是对的吗?这似乎是一个层次结构问题,我不知道如何解决这个问题.

交换的GIF和我的库存插槽游戏对象的屏幕截图:

http://imgur.com/kS1C1TL – GIF

enter image description here

我的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来制作更好的视觉效果:

新层次结构:

enter image description here

http://imgur.com/rjueuYK – GIF

我是如何进行库存不良操作的,或者我是否可以在Unity中使用某个游戏对象修复此层次结构问题?

解决方法

可能是因为您可能没有清空项目所在的原始插槽而导致此错误.这可能不是您要查找的确切答案,但在本教程中,与您所面临的问题类似的问题是解释.

https://www.youtube.com/watch?v=1gveNfidKPA&t=17m5s

希望这可以帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读