Game Development Reference
In-Depth Information
Back in the SpawnBunnies script's DropBundle function, add:
9.
bundle.rigidbody2D.isKinematic = false; // turn on the physics
10.
Save the script, and click Play.
The bundle drops nicely but leaves the scene. To stop it, you can create a Box Collider 2D at the
bottom of the Camera GUI's view.
1.
From Create Other, create a new Sprite and name it 2D Ground .
2.
Add it to the Sprite layer.
3.
Add a Box Collider 2D, and remove or disable the Sprite Renderer
component.
4.
Set the collider's Size to 50 , X, and 1 , Y.
5.
Move it somewhere below the battery and stork.
For final positioning, you will have to get the Camera GUI's viewing frustum showing in the
Scene view.
6.
Select the Camera GUI, and from the GameObject menu, choose
“Align View to Selected.”
7.
Move the 2D Ground so that the top of its box collider is barely above the
bottom of the Scene view.
8.
Click Play, and watch as the bundle drops and hits the ground.
9.
Stop Play mode, and adjust the 2D Ground object's position further if
necessary to put the bundle at the bottom of the Game view when it hits.
The next step is to register the collision and use it to trigger the Bundle Open clip. The collision
detection is easy, but you will also have to get the bundle back to its starting position and re-parented
in time for the next bunny drop. If you re-parent it to the Stork Group, which should already be
deactivated, it will inherit the deactivation. You can reuse a lot of the FlyBy's code.
1.
Create a new C# Script in the Game Scripts folder, and name it
BundleManager .
2.
Add the following variables:
public GameObject stork; // the Stork Group object
Vector3 startLocation; // the bundle's original location
public Animator animator; // the bundle's animator component
In an Awake function, store the start position:
3.
void Awake () {
startLocation = transform.localPosition; // store the starting location
}
Search WWH ::




Custom Search