Destroying a prefab with a boolean

Hi guys, I wanna destroy a prefab, but I can’t. This line of the code is working:

        gameController.contadorPontos = 0;
        for (int i = 0; i <= 13; i++)
        {
            if (espaços*.DenteCerto)*

{
gameController.contadorPontos++;//

}

}

if (gameController.contadorPontos == 14)
{
gameController.CasosResolvidos++;
Destroy(this.gameObject);
}

}
}
But, if I use something like this, it doesn’t work. It destroys the prefab, even if gameController.contadorPontos = 0:
for (int i = 0; i <= 13; i++)
{
if (espaços*.DenteCerto)*
{
gameController.contadorPontos++;

}

if (espaços*.DenteCerto == false)*
{
Destroy(this.gameObject);
}

}

I set DenteCerto to false in this script:
public class ValidadorEspaço1 : MonoBehaviour
{

private Transform ColliderTrans;
private PlayerController Player;

public bool ItemEmCima = false;
private GameObject EmCima;

// Start is called before the first frame update
void Start()
{
ColliderTrans = GameObject.FindWithTag(“PlayerCollider”).GetComponent();
Player = GameObject.FindWithTag(“Player”).GetComponent();

}

public GameObject DenteResp;
private GameObject ItemNaMandibula;
public bool DenteCerto;

private void Update()
{
//Debug.Log(DenteResp.transform.tag);

try
{
ItemNaMandibula = this.transform.GetChild(1).gameObject;

if (ItemNaMandibula.transform.tag == DenteResp.transform.tag)
{
DenteCerto = true;

}

if (ItemNaMandibula.transform.tag != DenteResp.transform.tag)
{
DenteCerto = false;
print(DenteCerto);

}

}
catch (Exception ex)
{
if (DenteResp.transform.tag == “Vazio” && !ItemEmCima)
{
DenteCerto = true;

}
else
{
DenteCerto = false;

}
}

if (DenteResp.transform.tag == “Vazio” && ItemEmCima)
{
DenteCerto = false;

}

}

What could I do in order to solve this issue? I don’t know what to do anymore.

I’m not quite sure of the intent here, but my thoughts are that you want to complete your loop and summing up the contadorPontos variable until the loop completes, but then destroy the object if any of the values of DenteCerto are false.

I think this might be what you are trying to achieve?

	bool destroyObject = false;
	
	for (int i = 0; i <= 13; i++)
	{
		if (espaços*.DenteCerto)*
  •  {*
    
  •  	gameController.contadorPontos++;*
    
  •  }*
    
  •  else*
    
  •  {*
    
  •  	destroyObject = true;	*
    
  •  }*
    
  • }*

  • if (destroyObject)*

  • {*

  •  Destroy(this.gameObject);*
    
  • }*

Hi man, I just wanna destroy the object if DenteCerto is false in this situation:

if (ItemNaMandibula.transform.tag != DenteResp.transform.tag)
            {
                DenteCerto = false;
            }

As I’ve explained before, in the image below, there’s a kind of mouth, and the black cubes are the spaces where the player must put the right teeth in. There are 14 spaces in the mouth, and each one of them means 1 point. So If, the player puts the right tooth in the right place he scores 1 point. Then, when he puts all the teeth that he needs, he must go to that red button and press backspace. If everything is correct, a congratulation message is activated and the prefab is destroyed and another case is spawned in the game.

However, if he puts a wrong tooth in a wrong place, DenteCerto is false and if the player goes to the red button and press backspace, I want to destroy the prefab as well, but this time he doesn’t score any point and another case is spawned in the game.

The first situation is working perfectly. The second isn’t ;(