Game Development Reference
In-Depth Information
In the PlantVeggies script, just below the
GameObject newVeggie =
line, add
7.
newVeggie.transform.parent = transform; // assign the clone to this object
8.
Save the script.
9.
Click Play, and inspect the Hierarchy view.
The clones are neatly stashed with their zones in the Hierarchy view during runtime (Figure
7-40
).
Figure 7-40.
The clones neatly parented to the zone objects that generated them
One little problem. Children inherit the transforms of their parents. The plants are scaled
after
they
are parented, so the plants pick up the Plant Zone's scale. Fortunately, if you assign the parent
after
the random scaling, everything is good.
10.
Move the parenting line
below
the scaling line in the PlantVeggies script.
11.
Save the script.
12.
Click Play, and make sure everything is working properly.
13.
Duplicate the Plant zone, and fill out the plants to suit your fancy.
Now you can move the zones so that the plants and zombie bunnies are hidden when the rest of the
garden is out of sight.
14.
Drag the Plant Zone, Zombie Zone, and Bun Holder objects onto the Garden
1 object.
15.
Click Play, and drive the gnome into the staging area.
16.
Check the Scene view to confirm that all the “extras” disappear when the
garden area is deactivated.
17.
Save the scene, and save the project.