it doesnt unactive,why it doesnt setactive(false) ?

my gameobjects that i specified in unity and in script doesnt set inactive

script:

public GameObject btn1;
public GameObject btn2;
public GameObject btn3;
public GameObject btn4;
public GameObject light1;

public float cbn = 0;

void Start () {
	
}


void Update () {

	
	if (cbn > 0)
	{
		btn1.SetActive(false);
	}
	if (cbn > 1)
	{
		
		btn2.SetActive(false);

	}
	if (cbn > 2)
	{
		
		btn3.SetActive(false);
	}
	if (cbn > 3)
	{
		
		btn4.SetActive(false);
		light1.SetActive(false);
	
	}
}

}

Hi,
Do you change cbn in other scripts?(cause its zero and you don’t check cbn ==0 in any conditions).

public float cbn = 0f; // put an “f” after the value because it is a float.
If you have a float on variable cbn, compare it with float data type by typing “f” next to the value you wanted to compare. I don’t know what you are trying to do with a bunch of if-statements not related to each other, but you can try else-if statement to produce 1 specific output as shown to my sample code below:

if(cbn > 0f)
{
    
    //disable button1
    btn1.SetActive(false);
    
}
else if(cbn > 1f)
{
    
    //disable button2
    btn1.SetActive(false);
    
}
    //continue else if statements till you're satisfied.

Have you also tried to change the value of “cbn” on the unity inspector? It’s public so it should be there plus your variable is being compared to those values on your if-statement every frame so it should work the moment the value of “cbn” has been changed.

If there are missing reference errors, you may want to assign those elements to the inspector to your public Gameobject variables.