2016-05-16 15 views
4

私は在庫システムに取り組んでいますが、現時点では在庫スポットを交換しています。現在、私はとして階層構造を持っている:私はそれだけで私はインベントリスロット4と例インベントリスロット1のために言って交換した場合に動作スワッピングしていたときにOnPointerEnterとOnPointerExitがUnityに登録されていません。5.3.4

enter image description here

は、今私が気づいたことはあるが、私はしていた場合たとえば、Inventory Slot 4とInventory Slot 1を交換してください。私のOnPointerEnterとOnPointerExitは登録されていません。これは正しいと思われますか?これは階層的な問題であると思われ、私はこれを解決する方法を知らない。

スワップと私のインベントリスロットゲームオブジェクトのスクリーンショットの

GIF:

http://imgur.com/kS1C1TL - GIF Inventory_Slotスクリプトのための私のOnPointersの

enter image description here

コード:また

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の上に移動しましたそれが意味をなさなければ後ろ向きにg。私はより良い視覚的にするためにGIFを投稿します:

新しい階層:

enter image description here

http://imgur.com/rjueuYK - GIF

は、私は私の在庫悪い習慣をやっている方法ですかユニティで何かがありますこの階層問題を解決するために私のゲームオブジェクトの1つに叩きつけることができますか?

答えて

1

このエラーは、アイテムが入っていた元のスロットを空にしていない可能性があるために発生している可能性があります。これはあなたが探している正確な答えではないかもしれませんが、このチュートリアルでは、説明してください。

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

は、この情報がお役に立てば幸いです。

関連する問題