[SOLVED]How to make a Tower Defense Game (E19 UPGRADE) - Unity Tutorial

I am following this tutorial but my building and selection is modified.
I have the following scripts:

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class Node : MonoBehaviour {

    [Header("Hover Color")]
    public Color hoverColor;

    [HideInInspector]
    public GameObject turret;
    [HideInInspector]
    public TurretBlueprint turretBlueprint;
    [HideInInspector]
    public Turret myTurret;

    private Renderer rend;
    private Color startColor;

    private ChangeRangeMat changeRangeMat;

    BuildManager buildManager;

    private void Start()
    {
        rend = GetComponent<Renderer>();
        startColor = rend.material.color;

        buildManager = BuildManager.instance;

    }

    public Vector3 GetBuildPosition()
    {
        return transform.position;
    }

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

        if (!buildManager.CanBuild)
        {
            return;
        }

        if (turret != null)
        {
            Debug.Log("Can't build here!");
            return;
        }

        BuildTurret(buildManager.GetTurretToBuild());
    }

    void BuildTurret(TurretBlueprint blueprint)
    {
        //Build a turret
        if (PlayerStats.Money < blueprint.cost)
        {
            Debug.Log("Not enough money to build that!");
            return;
        }

        if (blueprint != null && buildManager.CanBuild)
        {
            PlayerStats.Money -= blueprint.cost;

            GameObject _turret = (GameObject)Instantiate(blueprint.prefab, GetBuildPosition(), Quaternion.identity);
            turret = _turret;

            turretBlueprint = blueprint;
            //myTurret.Blueprint(blueprint);

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

            Destroy(buildManager.currentTurret.gameObject);
            turret.transform.GetChild(0).gameObject.SetActive(false);
            turret.transform.GetChild(1).gameObject.SetActive(false);
            BoxCollider bC = turret.AddComponent<BoxCollider>();
            bC.size = new Vector3(2, 34, 2);

            buildManager.BoughtTurret();

            //Debug.Log("Turret build!");
        }
    }

    private void OnMouseEnter()
    {
        if(EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        if (!buildManager.CanBuild)
        {
            return;
        }

        if (turret != null)
        {
            changeRangeMat = (ChangeRangeMat)FindObjectOfType(typeof(ChangeRangeMat));
            changeRangeMat.RangeMatRed();
            return;
        }
        else
        {
            rend.material.color = hoverColor;
            if (buildManager.currentTurret != null)
            {
                changeRangeMat = (ChangeRangeMat)FindObjectOfType(typeof(ChangeRangeMat));
                changeRangeMat.RangeMatWhite();
            }
        }
    }

    private void OnMouseExit()
    {
        if (buildManager.currentTurret != null)
        {
            rend.material.color = startColor;
            changeRangeMat = (ChangeRangeMat)FindObjectOfType(typeof(ChangeRangeMat));
            changeRangeMat.RangeMatRed();
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class Turret : MonoBehaviour {

    public Transform target;
    private Enemy targetEnemy;

    [Header("General")]
    public float range = 15f;

    [Header("Use Bullets (default)")]
    public float fireRate = 1f;
    private float fireCountdown = 0f;

    [Header("Use Ice")]
    public bool useIce = false;
    public float slowAmount = .5f;
    public float slowRange = 10;

    [Header("Use Fire or Lighting")]
    public bool useFireOrLighting;

    public int damageOverTime = 55;
    public float damageRadius;

    [Header("Unity Setup Fields")]
    public GameObject rangeView;
    public string enemyTag = "Enemy";

    public Transform partToRotate;
    public float turnSpeed = 10f;

    public GameObject bulletPrefab;
    public Transform firePoint;

    public GameObject weaponTrail;

    private Animator anim;

    private GameObject thisTurret;

    [HideInInspector]
    public GameObject turret;
    [HideInInspector]
    public Node node;
    [HideInInspector]
    public TurretBlueprint turretBlueprint;
    [HideInInspector]
    public bool isUpgradedL2 = false;
    [HideInInspector]
    public bool isUpgradedL3 = false;

    BuildManager buildManager;

    private void Awake()
    {
        anim = GetComponentInChildren<Animator>();
    }

    // Use this for initialization
    void Start ()
    {
        thisTurret = this.gameObject;

        InvokeRepeating("UpdateTarget", 0f, 0.5f);

        buildManager = BuildManager.instance;
    }

    public Vector3 GetBuildPosition()
    {
        return transform.position;
    }

    private void OnMouseDown()
    {
        Debug.Log("This turret is: " + thisTurret.ToString());
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        if (thisTurret != null)
        {
            buildManager.SelectTurret(this);
        }
    }

    //public void Blueprint(TurretBlueprint blueprint)
    //{
    //    turretBlueprint = blueprint;
    //}

    public void UpgradeTurret()
    {
        turretBlueprint = node.turretBlueprint;

        //Upgrade a turret
        if (isUpgradedL2 == false)
        {
            if (PlayerStats.Money < turretBlueprint.upgradeCostL2)
            {
                Debug.Log("Not enough money to upgrade that!");
                return;
            }

            if (turretBlueprint != null && buildManager.CanBuild)
            {
                PlayerStats.Money -= turretBlueprint.upgradeCostL2;

                //Get rid of the old turret
                Destroy(turret);

                //Build a new one
                GameObject _turret = (GameObject)Instantiate(turretBlueprint.upgradePrefabL2, node.GetBuildPosition(), Quaternion.identity);
                turret = _turret;

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

                Destroy(buildManager.currentTurret.gameObject);
                turret.transform.GetChild(0).gameObject.SetActive(false);
                turret.transform.GetChild(1).gameObject.SetActive(false);
                BoxCollider bC = turret.AddComponent<BoxCollider>();
                bC.size = new Vector3(2, 34, 2);

                buildManager.BoughtTurret();

                isUpgradedL2 = true;
            }
        }
        else if (isUpgradedL2 == true && isUpgradedL3 == false)
        {
            if (PlayerStats.Money < turretBlueprint.upgradeCostL3)
            {
                Debug.Log("Not enough money to upgrade that!");
                return;
            }

            if (turretBlueprint != null && buildManager.CanBuild)
            {
                PlayerStats.Money -= turretBlueprint.upgradeCostL3;

                //Get rid of the old turret
                Destroy(turret);

                //Build a new one
                GameObject _turret = (GameObject)Instantiate(turretBlueprint.upgradePrefabL3, node.GetBuildPosition(), Quaternion.identity);
                turret = _turret;

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

                Destroy(buildManager.currentTurret.gameObject);
                turret.transform.GetChild(0).gameObject.SetActive(false);
                turret.transform.GetChild(1).gameObject.SetActive(false);
                BoxCollider bC = turret.AddComponent<BoxCollider>();
                bC.size = new Vector3(2, 34, 2);

                buildManager.BoughtTurret();

                isUpgradedL3 = true;
            }
            else if (isUpgradedL2 == true && isUpgradedL3 == true)
            {
                Debug.Log("Max Level!");
            }
        }

        Debug.Log("Turret upgraded!");
    }

    void UpdateTarget()
    {
        GameObject[] enemies = GameObject.FindGameObjectsWithTag(enemyTag);
        float shortestDistance = Mathf.Infinity;
        GameObject nearestEnemy = null;

        foreach(GameObject enemy in enemies)
        {
            float distanceToEnemy = Vector3.Distance(transform.position, enemy.transform.position);
            if(distanceToEnemy <= range)
            {
                targetEnemy = enemy.GetComponent<Enemy>();
            }

            //Default Target
            if (distanceToEnemy < shortestDistance)
            {
                shortestDistance = distanceToEnemy;
                nearestEnemy = enemy;
            }
        
            //Nearest Target
            //if(distanceToEnemy <= range)
            //{
            //    shortestDistance = distanceToEnemy;
            //    nearestEnemy = enemy;
            //}
        }

        if(nearestEnemy != null && shortestDistance <= range)
        {
            target = nearestEnemy.transform;
            //targetEnemy = nearestEnemy.GetComponent<Enemy>();
            anim.SetBool("isAttacking", true);
            weaponTrail.SetActive(true);
        }
        else
        {
            target = null;
        }
    }
 
    // Update is called once per frame
    void Update ()
    {

        if(target == null)
        {
            anim.SetBool("isAttacking", false);
            weaponTrail.SetActive(false);
            return;
        }

        LockOnTarget();

        if(fireCountdown <= 0f)
        {
            Shoot();
            fireCountdown = 1f / fireRate;
        }

        fireCountdown -= Time.deltaTime;
    }

    void LockOnTarget()
    {
        //Target lock on
        Vector3 dir = target.position - transform.position;
        Quaternion lookRotation = Quaternion.LookRotation(dir);
        Vector3 rotation = Quaternion.Lerp(partToRotate.rotation, lookRotation, Time.deltaTime * turnSpeed).eulerAngles;
        partToRotate.rotation = Quaternion.Euler(0f, rotation.y, 0f);
    }

    void Shoot()
    {
        //anim.SetBool("isAttacking", true);
        //weaponTrail.SetActive(true);

        if(useFireOrLighting)
        {
            FireAndLighting();
        }
        else if(useIce)
        {
            IceAttack();
        }
        else
        {
            //Debug.Log("Use bullets!");
            GameObject bulletGO = (GameObject)Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
            Bullet bullet = bulletGO.GetComponent<Bullet>();

            if (bullet != null)
            {
                //Debug.Log("We shoot");
                bullet.Seek(target);
            }
        }
    }

    void FireAndLighting()
    {
        //target.GetComponent<Enemy>().TakeDamage(damageOverTime * Time.deltaTime);

        Collider[] colliders = Physics.OverlapSphere(transform.position, damageRadius);

        foreach (Collider collider in colliders)
        {
            if (collider.tag == "Enemy")
            {
                targetEnemy.TakeDamage(damageOverTime * Time.deltaTime);
            }
        }
    }

    void IceAttack()
    {
        //Debug.Log("It use Ice!");

        Collider[] colliders = Physics.OverlapSphere(transform.position, slowRange);
    
        foreach (Collider collider in colliders)
        {
            if (collider.tag == "Enemy")
            {
                targetEnemy.Slow(slowAmount);
                GameObject bulletGO = (GameObject)Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
                Bullet bullet = bulletGO.GetComponent<Bullet>();

                if (bullet != null)
                {
                    //Debug.Log("We shoot");
                    bullet.Seek(target);
                }
            }
        }
    }


    private void OnDrawGizmosSelected()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(transform.position, range);
    }
}
using UnityEngine;

public class BuildManager : MonoBehaviour {

    public static BuildManager instance;

    private void Awake()
    {
        //if (instance != null)
        //{
        //    Debug.Log("More than one BuildManager in scene!");
        //    return;
        //}
        //instance = this;

        //Check if instance already exists
        if (instance == null)
            instance = this;
        else if (instance != this)
            Destroy(gameObject);

        DontDestroyOnLoad(gameObject); //Keep this object when loading a new scene
    }

    [Header("Nodes")]
    public GameObject nodes;

    [Header("Build Effect")]
    public GameObject buildEffect;

    private TurretBlueprint turretToBuild;

    private GameObject currentTurretRange;

    private Turret selectedTurret;
    private Turret oldSelectedTurret;
 
    public TurretUI turretUI;

    [HideInInspector]
    public Transform currentTurret;

    public bool CanBuild { get { return turretToBuild != null; } }

    private void Update()
    {
        if (currentTurret != null)
        {
            Vector3 m = Input.mousePosition;
            m = new Vector3(m.x, m.y, transform.position.y);
            Vector3 p = Camera.main.ScreenToWorldPoint(m);
            currentTurret.position = new Vector3(p.x, p.y, p.z);
        }

        if (Input.GetMouseButtonDown(0) && currentTurret != null)
        {
            Destroy(currentTurret.gameObject);
        }
    }

    public void SelectTurret(Turret turret)
    {
        if(selectedTurret == turret)
        {
            Debug.Log("Selected turret is: " + selectedTurret.ToString());
            DeselectTurret(selectedTurret);
            return;
        }

        selectedTurret = turret;
        Debug.Log("Selected turret here is: " + selectedTurret.ToString());
        Debug.Log("Pasted turret here is: " + turret.ToString());
        if (oldSelectedTurret == null)
        {
            oldSelectedTurret = selectedTurret;
        }

        //Debug.Log("Selected turret is: " + selectedTurret.ToString());

        if (oldSelectedTurret != selectedTurret)
        {
            turretUI.Hide(oldSelectedTurret);

            //Debug.Log("Old in if Selected turret is: " + oldSelectedTurret.ToString());

            oldSelectedTurret = selectedTurret;
        }
        //Debug.Log("Current Selected turret is: " + selectedTurret.ToString());

        turretToBuild = null;

        turretUI.SetTarget(selectedTurret);
    }

    public void DeselectTurret(Turret turret)
    {
        if(turret != null)
        {
            Debug.Log("Turret to deselect is: " + turret.ToString());
            turretUI.Hide(turret);
            selectedTurret = null;
        }
        else
        {
            Debug.Log("Turret to deselect is null!");
        }
    }

    public void SelectTurretToBuild(TurretBlueprint turret, GameObject range)
    {
        turretToBuild = turret;
        //selectedTurret = null;
        currentTurretRange = range;
        nodes.SetActive(true);
        currentTurret = ((GameObject)Instantiate(turretToBuild.prefab)).transform;
        ChangeRangeMat changeRangeMat = (ChangeRangeMat)FindObjectOfType(typeof(ChangeRangeMat));
        changeRangeMat.RangeMatRed();
        currentTurretRange.SetActive(true);
        currentTurret.GetComponent<Turret>().range = 0f;
        DeselectTurret(selectedTurret);
    }

    public TurretBlueprint GetTurretToBuild()
    {
        return turretToBuild;
    }

    //public void BuildTurretOn(Node node)
    //{
    //    //Build a turret
    //    if(PlayerStats.Money < turretToBuild.cost)
    //    {
    //        Debug.Log("Not enough money to build that!");
    //        return;
    //    }

    //    if (currentTurret != null && CanBuild)
    //    {
    //        PlayerStats.Money -= turretToBuild.cost;

    //        GameObject turret = (GameObject)Instantiate(turretToBuild.prefab, node.GetBuildPosition(), Quaternion.identity);
    //        node.turret = turret;

    //        GameObject effect = (GameObject)Instantiate(buildEffect, node.GetBuildPosition(), Quaternion.identity);
    //        Destroy(effect, 5f);

    //        Destroy(currentTurret.gameObject);
    //        node.turret.transform.GetChild(0).gameObject.SetActive(false);
    //        node.turret.transform.GetChild(1).gameObject.SetActive(false);
    //        BoxCollider bC = node.turret.AddComponent<BoxCollider>();
    //        bC.size = new Vector3(2, 34, 2);

    //        BoughtTurret();

    //        //Debug.Log("Turret build! Money left: " + PlayerStats.Money);
    //    }
    //}

    public void BoughtTurret()
    {
        turretToBuild = null;
        currentTurret = null;
        nodes.SetActive(false);
        //currentTurretRange.SetActive(false);
        currentTurretRange = null;
    }
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class TurretUI : MonoBehaviour {

    public GameObject ui;

    private Turret target;

    [HideInInspector]
    public TurretBlueprint turretBlueprint;
    //[HideInInspector]
    //public TurretShop

    [Header("Buttons and Text")]
    public Text turretNameText;
    public Button sellButton;
    public Text sellText;
    public Button upgradeButton;
    public Text upgradeText;
    public Button nearestTargetButton;
    public Button weakestTargetButton;
    public Button strongestTargetButton;
    public Button BersekerButton;

    public void SetTarget(Turret _target)
    {
        target = _target;
        Debug.Log("Set Turret is: " + target);

        //Move the UI
        //transform.position = target.GetBuildPosition();

        target.gameObject.layer = LayerMask.NameToLayer("TurretImage");
        target.transform.GetChild(2).gameObject.layer = LayerMask.NameToLayer("TurretImage");
        target.transform.GetChild(0).gameObject.SetActive(true);
        target.transform.GetChild(1).gameObject.SetActive(true);;

        //Debug.Log(target.isUpgradedL2);
        if (!target.isUpgradedL2)
        {
            Debug.Log("Turret name: " + target.turretBlueprint.l1TurretName);
            turretNameText.text = target.turretBlueprint.l1TurretName;
            Debug.Log("Upgrade cost is: " + target.turretBlueprint.upgradeCostL2);
            upgradeText.text = "Upgrade: " + target.turretBlueprint.upgradeCostL2 + "$";
        }
        else if(!target.isUpgradedL3)
        {
            turretNameText.text = target.turretBlueprint.l2TurretName;
            upgradeText.text = "Upgrade: " + target.turretBlueprint.upgradeCostL3 + "$";
        }
        else if(target.isUpgradedL3)
        {
            turretNameText.text = target.turretBlueprint.l3TurretName;
            upgradeText.text = "LEVEL MAX";
        }

        ui.SetActive(true);
    }

    public void Hide(Turret target)
    {
        if(target != null)
        {
            target.gameObject.layer = LayerMask.NameToLayer("Default");
            target.transform.GetChild(2).gameObject.layer = LayerMask.NameToLayer("Default");
            target.transform.GetChild(0).gameObject.SetActive(false);
            target.transform.GetChild(1).gameObject.SetActive(false);
        }

        ui.SetActive(false);
    }

    public void Upgrade()
    {
        target.UpgradeTurret();
        BuildManager.instance.DeselectTurret(target);
    }
}

The problem is, when I try to upgrade the turret I get a null reference like this:
NullReferenceException: Object reference not set to an instance of an object
Turret.UpgradeTurret () (at Assets/Scripts/Turret.cs:99)
TurretUI.Upgrade () (at Assets/Scripts/TurretUI.cs:77)
UnityEngine.Events.InvokableCall.Invoke (System.Object[ ] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:153)
UnityEngine.Events.InvokableCallList.Invoke (System.Object[ ] parameters)

If I try to remove the line 99 from Turret script I get
NullReferenceException: Object reference not set to an instance of an object
Turret.UpgradeTurret () (at Assets/Scripts/Turret.cs:118)
TurretUI.Upgrade () (at Assets/Scripts/TurretUI.cs:77)

My question is how I can pass the turretBlueprint to the builded turret and how do I access the node is builded on ?

Another problem is that the turret name and upgrade costs are not updating

I solved this by passing

turret.GetComponent<Turret>().turretBlueprint = blueprint;

in line 74 of Node script and line 120 and 121 in Turret script to this

thisTurret = _turret;
thisTurret.GetComponent<Turret>().turretBlueprint = turretBlueprint;