Why my function don't works

Hi, I have a problem with unity, I have my code for drag and drop, and I have a function called dragged, but when I call it, nothing happens in unity, for example, I have a variable that is dragged, in the console is wrote that boolean is true, but in unity it is not, and I don’t know why this is happening.

My code:

HoverButton:

public class HoverButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    public InventorySlot hoverButton;

    public void OnPointerEnter(PointerEventData eventData)
    {
        InventorySlot comp = eventData.pointerCurrentRaycast.gameObject.transform.parent.GetComponent<InventorySlot>();

        if (comp == null)
            comp = eventData.pointerCurrentRaycast.gameObject.transform.parent.parent.GetComponent<InventorySlot>();

        if (comp != null)
        {
            hoverButton = comp;
        }
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        hoverButton = null;
    }

    private void Update()
    {
        if (hoverButton && !Inventory.instance.dadrop.isDragging)
        {
            if (hoverButton.item == null) return;
            if (!Input.GetKeyDown(KeyCode.Mouse1)) return;
            Inventory.instance.dadrop.dragItem(hoverButton, hoverButton.item);
            hoverButton.ClearSlot();
        }
    }
}

DragAndDrop.cs:

public class DragAndDrop : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    public Image dadicon;
    public bool isDragging;

    public InventorySlot oldButton;
    Item oldItem;
    public InventorySlot hoverButton;

    public void OnPointerEnter(PointerEventData eventData)
    {
        InventorySlot comp = eventData.pointerCurrentRaycast.gameObject.transform.parent.GetComponent<InventorySlot>();
       
        if (comp == null)
            comp = eventData.pointerCurrentRaycast.gameObject.transform.parent.parent.GetComponent<InventorySlot>();
       
        if (comp != null)
        {
            hoverButton = comp;
        }
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        hoverButton = null;
    }

    public void dragItem(InventorySlot _oldButton, Item _oldItem)
    {
        oldButton = _oldButton;
        oldItem = _oldItem;
        dadicon.gameObject.SetActive(true);
        dadicon.sprite = oldButton.icon.sprite;
        isDragging = true;
        Debug.Log(isDragging);
    }

    public void dropItem()
    {

        if (hoverButton != null)
        {
            if (hoverButton.icon.sprite)
            {
                oldButton.AddItem(hoverButton.item);
                hoverButton.ClearSlot();
                hoverButton.AddItem(oldItem);
            }
            else
            {
                hoverButton.AddItem(oldItem);
            }

            dadicon.gameObject.SetActive(false);
            oldButton = null;
            oldItem = null;

            isDragging = false;
        }
    }

    private void Update()
    {
        if (oldButton != null)
        {
            Vector2 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            dadicon.transform.position = Input.mousePosition;

            if (Input.GetKeyDown(KeyCode.Mouse1) || Input.GetKeyDown(KeyCode.Mouse0))
            {
                dropItem();
            }
        }
    }
}

Unity:

7105801--847405--upload_2021-5-4_13-29-37.png

Here is true

7105801--847408--upload_2021-5-4_13-30-10.png
But here isn’t

7105801--847411--upload_2021-5-4_13-30-28.png
This should be active

7105801--847414--upload_2021-5-4_13-30-39.png
But isn’t

I have one idea, I accidentally create a second instance of draganddrop.cs somewhere, but I don’t know where

1.- At HoverButton.Update you call dragItem with hoverbutton as parameter, and you know when you call dragItem, hoverButton is not null and MouseButton is pressed, since you checked it before.
2.- DragAndDrop.dragItem sets DragAndDrop.oldButton to the value you gave him (something not null). Now oldButton is not null. Dadicon gameObject is actived.
3.- At DragAndDrop.Update if youre pressing MouseButton (youre doing, you did it in order to call dragItem) and oldButton is not null (it isn’t since you’ve setted it at step 2) you set dadicon gameObjects active to false.

In summary, youre enabling dadicon gameObject, and immediatly disabling it.

Thanks, it works. Maybe I’m blind or something.