Game Development Reference
In-Depth Information
When applying the effect of
Food
on the collector, we use the values of
sizeIncremen-
tAmount
and
incrementDuration
. Since these variables are public, their values can be set
from the inspector. This makes it possible to make the two types of food we want to have.
Now we can create two game objects, say, cubes with different sizes and textures, and at-
tach to each one
YRotator
,
Collectable
, and
Food
scripts. The only difference regarding the
scripts is going to be in the values of
sizeIncrementAmount
and
incrementDuration
vari-
ables. So let's make the “green food” with size increment of 2 and a duration of
7.5 seconds, and the “red food” with size increment of 3.5 and a duration of 5 seconds.
These types of food are shown in Illustration 37. The final result can be seen in
scene10
in
the accompanying project.
Illustration 37:
Red food object (right) and green food object