Game Development Reference
In-Depth Information
table 1.4 Shortcut arithmetic operations and their equivalent longhand
Shortcut
Longhand
Description
Adds one to the value of the variable
and replaces the original value with
the new one
i++
i = i + 1
Takes one away from the value of the
variable and replaces the original value
with the new one
i——
i = i — 1
Adds two to the value of the variable
and replaces the original value with
the new one
i += 2
i = i + 2
Takes two away from the value of the
variable and replaces the original value
with the new one
i —= 2
i = i — 2
Multiplies the value of the variable by
two and replaces the original value
with the new one
i *= 2
i = i * 2
Divides the value of the variable by two
and replaces the original value with the
new one
i /= 2
i = i / 2
Unity Hands On
for Loops
Step 1. Download Chapter One/forloop.zip from the Web site, unzip,
and open in Unity. In the Project, double-click on stacked to open the
scene. The Scene will appear empty. Attached to the Main Camera
is the script called stackedSpheres.js . Play the file. A vertical stack of
spheres will appear in the Game.
Step 2. Open stackedSpheres.js with the script editor. The code used to
create the stack of spheres is inside the Start function. Each sphere is
created individually and its y position is changed by 1 with each new
sphere.
Step 3. Modify each line like this
sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
to this
sphere = GameObject.CreatePrimitive(PrimitiveType. Cube );
Step 4. Save the script and replay the application. The stack of
spheres will be replaced with a stack of cubes.
Search Nedrilad ::




Custom Search