Can't update variable.

I’m trying to reset the variable isUpgraded=0 again because I have a bug when enemies destroying turrets that are lvl2 or 3 because the variable isUpgraded doesn’t update in the NodeUI nor in the Node but I have a Debug.Log in the Node that says me it has changed.

Here the code for the turret destroying:

    public void TurretTakeDamage(float amount)
    {
        turretHealth -= amount;

        turretHealthBar.fillAmount = turretHealth / startTurretHealth;

        if (turretHealth <= 0)
        {
            node.ResetUpgrade();
            Die();
           
        }
    }

    void Die()
    {
       
        Destroy(gameObject);
       
    }

And here the ResetUpgrade() in the Node class:

    public void ResetUpgrade()
    {
        isUpgraded = 0;
        Debug.Log("isUpgraded is" + isUpgraded);
    }

So that Debug says isUpgraded is0 but in the Inspector while running the game it doesn’t change from 1.
Any ideas what I could do?

then it would suggest the node it changed was not the one you thought

Well, I have only one Node prefab and I put it in the turret prefab in the inspector, and the Node code is from that Node prefab. Even more, I’ve got a SellTurret function in the Node that does mostly the same and it works.

    public void SellTurret()
    {
        PlayerStats.Money += turretBlueprint.GetSellAmount();

        GameObject effect = (GameObject)Instantiate(buildManager.sellEffect, GetBuildPosition(), Quaternion.identity);
        Destroy(effect, 5f);

        Destroy(turret);
        turretBlueprint = null;
        ResetUpgrade();
    }

its impossible to tell with whats here

Well the Sell function works like that, when I press the click it executes this:

    void OnMouseDown()
    {
        if (EventSystem.current.IsPointerOverGameObject())
            return;

        if (turret != null)
        {
            buildManager.SelectNode(this);
            return;
        }

        if (!buildManager.CanBuild)
            return;

        BuildTurret(buildManager.GetTurretToBuild());
    }

Then in the buildManager:

public void SelectNode(Node node)
{
    if (selectedNode == node)
    {
        DeselectNode();
        return;
    }

    selectedNode = node;
    turretToBuild = null;

    nodeUI.SetTarget(node);
}

Then in the nodeUi script:

 public void SetTarget(Node _target)
{
     target = _target;

     lvl = target.isUpgraded;

     transform.position = target.GetBuildPosition(); // podria ser transform position pero eso seria el centro del nodo i queremos .5 mas arriba


     if(lvl == 0)
     {
         Debug.Log("Nivel de upgradeamiento" + target.isUpgraded);
         textUpgrade.text = "UPGRADE";
         upgradeCost.text = "$" + target.turretBlueprint.upgradeCost1;
         upgradeButton.interactable = true;
     }else
     {
         if(lvl == 1)
         {
             textUpgrade.text = "UPGRADE";
             upgradeCost.text = "$" + target.turretBlueprint.upgradeCost2;
             upgradeButton.interactable = true;
         }
         else
         {
             textUpgrade.text = "MAX";
             upgradeCost.text = "LEVEL";
             upgradeButton.interactable = false;
         }
           
     }

     sellAmount.text = "$" + target.turretBlueprint.GetSellAmount();

     ui.SetActive(true);
}

    public void Sell()
    {
        target.SellTurret();
        BuildManager.instance.DeselectNode();
    }

And then the function in the other comment, I think I should do smth like that but I don’t know how to simulate the OnMouseDown() with my turret being destroyed because I need the Node.