Game Development Reference
In-Depth Information
Next, take a look at the values for the parameters. The Ear Length's value, a float number, does
not require an f after the number in the Inspector. The description variable was initialized as an
empty string, "" . The value for the isWarmBlooded variable, of Boolean type, appears as a check box.
Because it was not initialized in the script, it defaults to false , or off.
Introducing Unity-Specific Variables
The last variable is a type uniquely available in Unity. Because a gameObject is an instance of
the GameObject class, it is also a type. The big difference between Unity-specific types and the
usual types found in most programming languages is that they cannot be initialized when the
variable is declared. They can be “found” in a function during runtime, or they can be loaded in the
inspector manually. The former is best when all of the instances of the script will be using the same
gameObject. The latter is easy when you only have to do it once or twice. Let's load something into
that parameter.
1.
Make sure you are not in Play mode.
2.
Open the Garden Plants object in the Hierarchy view.
3.
Locate the Cabbage.
4.
Select the StoneGardenBench.
5.
Locate the Favorite Food parameter in its Variables Test component.
Whenever you declare a variable as any of the available Unity types, the parameter will show that
“none” has been assigned and it will show the type that is expected (Figure 5-12 ).
Figure 5-12. The Favorite Food parameter waiting for a value of type Game Object
6.
Drag the Cabbage from the Hierarchy view into the StoneGardenBench's
Favorite Food parameter (Figure 5-13 ).
 
Search WWH ::




Custom Search