OnPointerEnter and OnPointerExit are not registered in Unity 5.3.4

I am working on an inventory system, and at the moment I am studying the replacement of inventory spots. I currently have a hierarchy:

enter image description here

Now, what I noticed when I exchange it works only if I had to change the word, for example, in inventory slot 1 with inventory slot 4. BUT, if I have to change it, for example, inventory slot 4 with inventory slot 1 my OnPointerEnter and OnPointerExit are not logged, should this be correct? This seems to be a hierarchy problem, and I don't know how to solve it.

Swap GIF and screenshot of my GameObject slot machine:

http://imgur.com/kS1C1TL - GIF

enter image description here

Code of my OnPointers for Inventory_Slot script:

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;
    }
}

, Inventory 5 Inventory 1 , , . GIF, :

:

enter image description here

http://imgur.com/rjueuYK - GIF

- Unity, , ?

+4

All Articles