0
\$\begingroup\$

I'm trying to enable and disable GameObject (canvas) using this code:

public int canvaslevel = 1;
public GameObject one;
public GameObject two;
public GameObject three;



void Update(){
    if(canvaslevel=1){
        one.SetActive(true);
        two.SetActive(false);
        three.SetActive(false);
    }
    if(canvaslevel=2){
        one.SetActive(false);
        two.SetActive(true);
        three.SetActive(false);
    }
    if(canvaslevel=3){
        one.SetActive(false);
        two.SetActive(false);
        three.SetActive(true);
    }
}

but it doesn't work!!!

error:

Cannot implicitly convert type int' tobool'

\$\endgroup\$
3
\$\begingroup\$

Use canvaslevel==1 instead of canvaslevel=1. Change to canvaslevel==2 and canvaslevel==3 as well.

You need to check equivalence not assign a value.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.