public bool CheckIfCanSpawn(Entity.Owner owner)
    {
        bool can = false;

        if (owner == Entity.Owner.Player)
        {
            foreach (Entity entity in PlayerEntities)
            {
                if (entity.gameObject.GetComponent <Troop>() != null &&
                    entity.gameObject.GetComponent <AbstractNPCBrain>().currentState != null &&
                    entity.gameObject.GetComponent <AbstractNPCBrain>().currentState.stateName != STATE.Idle)   //is moving or attacking
                {
                    can = false;
                }
            }
            if (currentTroopsPlayerSpawned >= MaxTroopsSpawned)
            {
                can = false;
            }
            else
            {
                can = true;
            }
        }
        else if (owner == Entity.Owner.AI)
        {
            if (currentTroopsAISpawned >= MaxTroopsSpawned)
            {
                can = false;
            }
            else
            {
                can = true;
            }
        }

        return(can);
    }
    public void SpawnEntity(CellBehaviour cell, ENTITY _entityToSpawn, Entity.Owner owner)
    {
        if (!_levelController.CheckIfCanSpawn(owner))
        {
            return;
        }

        GameObject entitySpawned    = null;
        GameObject entityToSpawn    = null;
        AudioClip  entitySpawnSound = null;

        switch (_entityToSpawn)
        {
        case ENTITY.None:
            Debug.Log("Antes debes seleccionar una tropa! ");
            FindObjectOfType <AttackButtonController>().GetComponent <AttackButtonController>().ShowButtons();
            soundManagerRef.PlaySingle(soundManagerRef.incorrectMovement);
            break;

        case ENTITY.Prisioner:
            lastTroopSpawned = ENTITY.Prisioner;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Prisioner.ToString() + owner.ToString());
            entitySpawnSound = soundManagerRef.cageSoundSpawn;
            break;

        case ENTITY.Launcher:
            lastTroopSpawned = ENTITY.Launcher;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Launcher.ToString() + owner.ToString());
            entityToSpawn.GetComponentInChildren <ParticleSystem>().Stop();
            entitySpawnSound = soundManagerRef.launcherSoundSpawn;
            break;

        case ENTITY.Tank:
            lastTroopSpawned = ENTITY.Tank;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Tank.ToString() + owner.ToString());
            entitySpawnSound = soundManagerRef.tankSoundSpawn;
            break;

        case ENTITY.Wall:
            lastTroopSpawned = ENTITY.Wall;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Wall.ToString() + owner.ToString());
            break;

        case ENTITY.Turret:
            lastTroopSpawned = ENTITY.Turret;
            entityToSpawn    = Resources.Load <GameObject>("Prefabs/Enemies/" + ENTITY.Turret.ToString() + owner.ToString());
            entitySpawnSound = soundManagerRef.turretSoundSpawn;
            break;
        }

        if (entityToSpawn == null)
        {
            return;
        }
        int  bloodCost   = entityToSpawn.GetComponent <Entity>().bloodCost;
        bool bloodEnough = owner == Entity.Owner.Player ? bloodCost <= _bloodController.GetCurrentPlayerBlood() : bloodCost <= _bloodController.GetCurrentAIBlood();

        if (bloodEnough)
        {
            if (entityToSpawn != null)
            {
                soundManagerRef.PlaySingle(entitySpawnSound);
                entitySpawned = Instantiate(entityToSpawn, new Vector3(cell.transform.position.x, 0f, cell.transform.position.z), entityToSpawn.transform.rotation);
                entitySpawned.GetComponent <Entity>().SetEntity(owner);
                entitySpawned.GetComponent <Entity>().entityType = lastTroopSpawned;

                if (owner == Entity.Owner.Player)
                {
                    currentEntitySelected = ENTITY.None;
                }

                //Node node = _influenceMapComponent.GetNodeAtLocation(new Vector3(cell.transform.position.x, 1f, cell.transform.position.z));

                OnSpawnedTroop?.Invoke(entitySpawned.GetComponent <Entity>());

                if (owner == Entity.Owner.Player)
                {
                    _levelController.currentTroopsPlayerSpawned++;
                    _bloodController.DecreasePlayerBloodValue(entitySpawned.GetComponent <Entity>().bloodCost);
                }
                else if (owner == Entity.Owner.AI)
                {
                    Debug.Log("decreasing blood");
                    _levelController.currentTroopsAISpawned++;
                    _bloodController.DecreaseAIBloodValue(entitySpawned.GetComponent <Entity>().bloodCost);
                }

                FindObjectOfType <AttackButtonController>().GetComponent <AttackButtonController>().HideButtons();
                cell.GetComponent <CellBehaviour>().entityIn = entitySpawned.GetComponent <AbstractNPCBrain>();
                entitySpawned.GetComponent <Entity>().cell   = cell.GetComponent <CellBehaviour>();
            }
        }

        else
        {
            Instantiate(Resources.Load <GameObject>("Prefabs/Popups/SimpleInfoPopup")).GetComponent <SimpleInfoPopupController>().SetPopup("PLAYER", "NOT ENOUGH\nBLOOD");
        }
    }