Game Development Reference
In-Depth Information
Listing 1.26 Script to Change Cubes to Random Colors
in Each Main Loop
function Update ()
{
for(var i:int = 0; i < 9; i++)
{
aP[i].renderer.material.color =
new Color(Random.Range(0.0,1.0),
Random.Range(0.0,1.0),
Random.Range(0.0,1.0));
}
}
Step 6. Save and play. The cubes will change colors constantly. An
explanation of the Color function is given in later sections.
1.5.8 Objects
Objects are complex data types. They consist of a bunch of variables
(sometimes called properties ) and functions (sometimes called methods ).
In most of the previous examples, you've already worked with objects.
A Game Object is an object. A cube is an object. Most of the items you
work with when coding that aren't integers, floats, strings, or characters
are objects. A class defines the data type of an object.
Let's assume we have a simple class called Square . The class definition acts
as a template for making many Square objects. Figure 1.32 illustrates how
Class
Objects
color = gray
rotation = 45
size = 3
Square
color = black
rotation = 20
size = 2
Variables
color = white
rotation = 0
size = 2
color
rotation
size
color = black
rotation = 0
size = 1
Functions
Rotate
Fig 1.32 A Square class and four
instances of the class.
Search Nedrilad ::




Custom Search