Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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'

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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