Why is that an error??? Plz help ( newby )

Hey,

I want to enalbe / disable a box. If I only endable/disable the renderer, the code works. I need to enable/disable the collider, too. But when I add this line to the code, it is bugged. Can somebody explain why?

((( I also tryed gameObject. active = true/false, but if once deactivated, I cant reactiveate it again. )))

void Update() {

if(Input.GetKeyDown(KeyCode.I))
    blackScreen = !blackScreen;

if(blackScreen)
{
    collider.enabled = true;
    renderer.enabled = true;
}
else if(!blackScreen)
{
    renderer.enabled = false;
    collider.enabled = false;
}
}

A short explanation what Duney has done:

you forgot to put both enabled statements into parentheses. If you want to execute more than one statement in an if clause you have to put all statemnes between { } parentheses.

In your code only the first statement after the if and else was executed depending on the value of blackScreen. The last statement

collider.enabled = false;

was executed always.

One minor correction:

Parentheses = ( )
Braces = {}
Brackets= [ ]

And maybe one more small point of clarification:

Square Brackets = [ ]
Angle Brackets = <>

:wink: