Game Development Reference
In-Depth Information
Figure 5-4. The new Variables Test component on the StoneGardenBench object
Note that the “CamelCase” script name now sports a space between the two words and “(Script)”
reminds you what kind of component it is. Conspicuously missing, however, is the variable you
added to the script.
Exposing Variables to the Inspector
As a default, C# variables are automatically “private.” Not only are they not accessible by other
scripts, they are not exposed to the Inspector. With Unity's version of JavaScript, the default
is publicly accessible. With both JavaScript and C# in Unity, you have the option of making it
accessible to other scripts but not exposed to the Inspector by marking it as internal . Let's see about
exposing the variable to the Inspector.
6.
Change your variable line to read as follows:
public int legs;
7.
Save the script.
8. Click back in the Unity editor to change the focus.
The Inspector updates, and the legs variable is now exposed (Figure 5-5 ).
 
Search WWH ::




Custom Search