Game Development Reference
In-Depth Information
Step 10. Using the values you wrote down, hard code the new
positioning information into the key pickup code as shown
in Listing 6.5 . These values set the local transform of the key.
It will still move with its parent, the right hand.
Listing 6.5 Setting the Local Transform for a Child Game
Object
var attachPoint: GameObject;
function OnControllerColliderHit (hit :
ControllerColliderHit)
{
if(hit.gameObject.tag == "key")
{
Destroy(hit.gameObject.collider);
hit.gameObject.transform.parent
=attachPoint.transform;
hit.gameObject.transform.localPosition =
Vector3(-0.0009,0.0001,0.0002);
hit.gameObject.transform.localScale =
Vector3(0.005,0.005,0.005);
hit.transform.localEulerAngles =
Vector3(299,286,312);
}
}
Step 11. Play. The avatar will now pick up the key and hold it
correctly.
Step 12. Because the avatar is already holding the wrench object
it seems logical that it should drop it after picking up the key.
You'll then want to be able to pick it up again. The first step in
achieving this is to select the wrench in the Hierarchy and
set its tag to “key.”
Step 13. Play. Pause the game and take note of the transform values
for the wrench as you did for the key. These will be used to reset the
wrench's position when it is picked up again.
Step 14. Now modify the pickup.js script to that shown in
Listing 6.6 . The code keeps a record of the currently held object with
the currentObj variable. This is used to attach and drop the object.
Search Nedrilad ::




Custom Search