Game Development Reference
In-Depth Information
Rotation turns an object about a given axis by a specified number of degrees.
An object can rotate about its x , y , or z axes or the world x , y , or z axes.
Combined rotations are also possible. These cause an object to rotate around
arbitrary axes defined by vector values. The Unity JavaScript to rotate an
object about 90° about the y axis is
this.transform.Rotate(Vector3.up, 90);
To rotate 90° around the x axis, the script is
this.transform.Rotate(Vector3.right, 90);
and to rotate 90° around the z axis, the script is
this.transform.Rotate(Vector3.forward, 90);
Some of these rotations are illustrated in Figure 2.14 .
Finally, scaling changes the size of an object as shown Figure 2.15 . An object
can be scaled along its x , y , or z axis. This can be achieved in Unity JavaScript
by setting each scale value individually, thus:
this.transform.localScale.x = 3;
this.transform.localScale.y = 0.5;
this.transform.localScale.z = 10;
Rotate(Vector3.right,90)
z
y
x
z
y
x
z
y
default position
x
Rotate(Vector3.up,90)
Fig 2.14 Rotating a game object with the Rotate function.
 
Search Nedrilad ::




Custom Search