Game Development Reference
An important thing to note in Table 1.3 is the use of = versus ==. One equal
sign means assign or place a value into a variable, and the double equal sign
means compare two values. First-time programmers often get these mixed up
but with practice the differences become clear.
Unity Hands On
Step 1. Download Chapter One/Operators.zip from the Web
site, unzip, and open in Unity. In the Project, double-click on
dynamicResize to open the scene. In the Scene you will see a
small white sphere. Attached to the sphere is the script called
Step 2. Double-click on grow.js in the Project to open the script editor.
Note that there is already a variable added called growthRate . Modify
the script to reflect the one in Listing 1.12 .
Listing 1.12 Script to Grow a Game Object by 0.05 in Scale
in Each Game Update
var growthRate: float = 0.05;
function Update ()
= transform.localScale.x + growthRate;
= transform.localScale.y + growthRate;
= transform.localScale.z + growthRate;
Step 3. Save the script and play in Unity. Note how the sphere
grows slowly in size. This will continue until you stop playing. The
Update function continues to run over and over again while the
application is playing. Functions will be explored in depth later.
For now, a simplistic explanation of what is happening is that the
growthRate is continually being added to the current value of the
localScale, thus updating it.
Step 4. Click on the Sphere in the Hierarchy. Ensure that you can see
the Scale part of the Transform component in the Inspector. Now
press play and watch as the x , y , and z values of the scale change
Call it revolve . To the file add the code in Listing 1.13 .