Game Development Reference
In-Depth Information
Step 12. In the script, add two more variables for adjusting the Y and
Z scales and some code to link these values to the cubes transform
component. The full listing of the new code is shown in Listing 1.11 .
Modifications are shown in bold .
Do not use bold in your own code. Scripting should have no font effects
whatsoever. Any coloration or bolding put in by the editor is for your
own readability. It is put in automatically. Make use of this coloration and
bolding to check that you have keywords spelled correctly.
Listing 1.11 A Script to Modify X , Y , and Z Scales
of a Game Object
var objScaleX: float = 2.0;
var objScaleY: float = 0.2;
var objScaleZ: float = 0.5;
function Start ()
transform.localScale.x = objScaleX;
transform.localScale.y = objScaleY;
transform.localScale.z = objScaleZ;
Step 13 . Save the script, return to Unity, and play to see the changes
take effect. Change the values of these scales in the Inspector to
experiment with the shape of the cube as the differing scales are
When you start programming it is extremely common to make typing
errors and to leave out parts of code such as semicolons on the end of
lines or missing brackets. If you make a mistake, Unity will detect it and
give an error message. It shows up in red at the very bottom of the Unity
window, as shown in Figure 1.28 . If you get an error, double-click on the
red message and Unity will take you to the line in the script editor where
the error occurred. From there you can fix it, save the file, and return to
Unity to try again.
Search Nedrilad ::

Custom Search