GetComponent<CanvasRenderer>().enabled = !GetComponent<CanvasRenderer>().enabled;

            GetComponent<CanvasRenderer>().enabled = !GetComponent<CanvasRenderer>().enabled;

//Why I can't do this?

//Sorry for the title

I dunno. Why can’t you do it? Does it throw an error? Not work? Make unity blow up? Set fire to your hard drive? Hack into the US government computers and launch nukes at Saturn?

3 Likes

according to the scripting reference… there isn’t an “enabled” attribute

(could just be “docs :roll_eyes::eyes:” though)

2 Likes

You’re not wrong - it’s on Behaviour: http://docs.unity3d.com/ScriptReference/Behaviour-enabled.html

2 Likes

What the OP probably wants to do is call SetActive in the GameObject. This will do essentially the same thing.

1 Like

Not necessarily. If you want to turn off a single component, you don’t want to turn off the whole object. That said, in this context, you are most likely right, especially since you can’t disable a canves renderer component, but it is important to note the difference between the two.

1 Like

Well i can SetAlpha wich fit what i was looking for, thanks :smile: