Game Development Reference
In-Depth Information
// add the bundle back into the Stork Group's transform
transform.parent = stork.transform;
// reset the start position
transform.localPosition = startLocation;
// reset the rotation
Vector3 tempRot = transform.localEulerAngles;
tempRot.z = zRotation;
transform.localEulerAngles = tempRot;
transform.parent = bundle.transform; // move the baby zb into the bundle group
}
In the Deactivator , you allow 4-5 seconds for the Baby ZBs to bounce around before they wink out
of existence. They are then returned to their initial locations and re-parented to the Stork Group,
where they inherit its deactivation. After resetting their orientations, the physics are turned off, and
then any residual velocity is cleared. Having made sure they are safely in the Stork group and their
position is correct, you move them into the bundle group for the next pass.
10.
Save the script.
11.
Drag the script onto the Baby ZB .
12.
Drag the Baby ZB into the Prefabs' Characters folder to create a prefab for it.
13.
Drag 3 or 4 more Baby ZBs into the scene, and arrage them in the bundle.
To set all of the Baby ZBs in motion, you will call their Escape function in the Bundle's
OnCollisionEnter function. You could use BroadcastMessage to contact all of the Baby ZBs that will
reside on the Bundle parent, but it tends to be rather slow, as it must check each component looking
for the function you want to trigger. To manage the Baby ZBs here, you will put them into an array at
the start of the game and iterate through them to call their Escape functions.
1.
Open the BundleManager script, and add the following variable for the array:
GameObject[] buns2D; // array to hold the baby buns sprites
2.
In the Awake function, collect the Baby ZBs'as follows:
buns2D = GameObject.FindGameObjectsWithTag ("Buns2D");
With FindGameObjectsWithTag , the scene will be searched for all objects with the specified tag.
The collected objects are put into an array of type GameObject. The Baby ZBs will require the tag.
3.
Click the Tag drop-down menu on the Baby ZB, and Add Tag.
4.
In the next open Tags slot, add Buns2D .
5.
Select the Baby ZB again, and assign the Buns2D tag to it.
Search WWH ::




Custom Search