Unity 3.x Game Development by Example Beginner's Guide
上QQ阅读APP看书,第一时间看更新

The Renderer class

The Renderer class lists a bunch of stuff that might look like so much gibberish to you. It has these lists:

  • Variables
  • Messages sent
  • Inherited variables
  • Inherited functions
  • Inherited class functions

From that list, the only familiar word might be "functions", which we just learned are reusable bundles of code (or endlessly eatable sandwiches, if you prefer). As we write more code in this chapter, we'll come to understand what variables are. For now, focus on the things listed under the Variables section.

One of the variables is called enabled. Do you remember when you wrote renderer.enabled = false;? You've already used a variable, perhaps without knowing it. And, check it out—some of the other things that we noticed in the Mesh Renderer component are listed here. There are variables called castShadows and receiveShadows, which we saw as checkboxes in the Inspector panel. There are also some material-related variables. At the bottom of the list, there's a variable called isVisible , which appears to do something different than the enabled variable.

Have a go hero - Pulling the wings off of flies

If you were the type of kid who disassembled your parents' clock radio, or got up close and personal with the insects in your backyard to see what made them tick, this is your time to shine. The Language Reference is your gateway to every special reserved word ("keyword") in the Unity language. Try clicking on the enabled variable in that list. The resulting page not only repeats the explanation of the variable, but it also provides an example of how you might use that variable in code. You can even use the drop-down lists on the right to see the C# and Boo translations. (Go ahead check them out! Fortune favors the bold.)

If you're wired a certain way, you've already thrown this book down and are eagerly scouring the Language Reference looking for code you can mess around with. That's okay. We'll be here when you get back. If you are still a little wary of this foreign language and would like a little more guidance using it, read on.