Game Development Reference
In-Depth Information
In the Update function, add the following:
6.
// update the target's location
target = new Vector2(targetTransform.position.x,targetTransform.position.z);
// get the distance between the target and source
float dist = Vector3.Distance(source, target);
print (dist);
7.
Save the script, and add it to the Common Wall 2's GardenGates object.
8.
Drag the Gnomatic Garden Defender onto its Target Transform parameter.
9.
Drag the Main Camera onto its Camera parameter.
10.
Click Play, and watch the distance in the console as you drive back and forth
through the gateway.
The distance should be at about 0 when the gnome goes through the doors (Figure 7-26 ).
Figure 7-26. Almost at doors, distance nearing 0
Before you go any farther, there is a logic problem to solve. The camera is currently controlled by the
SmoothFollow script. A solution is to link the camera to a dummy object that has the SmoothFollow so
that the camera distance can always be adjusted relative to the dummy's position. While this sounds
like a painful adjustment, because of Unity's component architecture, it will actually be quick and easy.
1.
Duplicate the Main Camera, and drag one onto the other.
2.
Name the parent Main Camera Target .
3.
Remove its Camera, Audio Listener, GUILayer, and Flare Layer components.
 
Search WWH ::




Custom Search