Game Development Reference
In-Depth Information
Step 19. At this stage, balls will fall straight through the beakers. To
add collisions, find the “Erlenmeyer1” meshes for each beaker object
and attach a Component > Physics > Mesh Collider to each one.
Ensure that the Mesh setting for this collider is set to “Erlenmeyer1” as
shown in Figure 4.4 .
Fig 4.4 Attaching a Mesh Collider to
the Mesh renderer of an object.
Step 20. Play. The balls will now collide with the beakers. If you
want the balls to fall faster, lower their drag value in the ball prefab.
However, as the game play starts to take shape you'll be glad that
they are falling more slowly.
Step 21. Modify spawn.js to that shown in Listing 4.4 . This will add
an array of materials to the script so that each ball spawned can be
assigned a random color. The shader for the material is changed to
Diffuse, as we will be using the existing transparent-colored materials
on the beakers, but we don't want the balls to be transparent.
Listing 4.4 Coloring a Game Object Using an Array
of Materials
var ball:GameObject;
var materialArray: Material[];
function Update ()
if(Random.Range(0,200) < 1)
var ballStartPosition = new Vector3(
var sphere : GameObject =
Instantiate(ball, ballStartPosition,
Search Nedrilad ::

Custom Search