Game Development Reference
In-Depth Information
Fig 1.26 A private and exposed
variable in the Inspector.
Unity Hands On
JavaScript Variables
In this hands-on session you will create variables of your own to modify
the scale of a cube and explore the differences between private and
exposed variables. The starting file is supplied on the Web site for download.
Step 1. Download Chapter One/Variables.zip from the Web site; unzip.
Run Unity and open the project by using File > Open Project, select
Open Other , and browse for the Variables directory. In the Project,
double-click on cubeResize to open the scene. In the Scene you will
see a white cube. Attached to the cube is the script from Listing 1.10 .
The objScaleX variable is private and therefore not visible in the
Inspector when the cube is selected.
Step 2. Highlight Cube in the Hierarchy and look at the resize script
in the Inspector at the very bottom. You'll notice that there are no
variables visible. Press play to watch the x scale of the cube change.
Remember to press stop when finished.
Step 3. Double-click on resize.js in the Project to open with a code
editor. Note that the objScaleX variable has the keyword private
at the beginning of the declaration.
Step 4. Remove the private keyword and save the file.
Search Nedrilad ::




Custom Search