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
var attachPoint: GameObject;
function OnControllerColliderHit (hit :
if(hit.gameObject.tag == "key")
hit.gameObject.transform.localPosition =
hit.gameObject.transform.localScale =
hit.transform.localEulerAngles =
Step 11. Play. The avatar will now pick up the key and hold it
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