Game Development Reference
In-Depth Information
Step 25. To test out another key, duplicate the RedKey in the
Hierarchy. Move its position in the environment. Rename the key
GreenKey .
Step 26. Create a green-colored material and place this on the
GreenKey object so that it appears green.
Step 27. Modify pickup.js, just below the previous change, to register
the GreenKey being picked up as shown in Listing 6.11 .
Listing 6.11 Picking up Another Inventory Item
. . .
hit.gameObject.transform.localPosition =
hit.gameObject.transform.localScale =
hit.transform.localEulerAngles =
if( == "RedKey")
Camera.main.GetComponent("gui").theRedKey = hit.
else if( == "GreenKey")
Camera.main.GetComponent("gui").theGreenKey = hit.
. . .
Step 28. Play. The red and green keys are not recorded as having been
picked up by the character. There is now only one problem. Currently
the picked-up item is being thrown away when another is picked
up. We want the character to keep hold of the key. To fix this, modify
pickup.js as shown in Listing 6.12 .
Step 29. The code in Listing 6.12 will now cause any previously held
object to become invisible. It will still be in possession of the character
but just not seen in the game environment. Only the last picked-up
item is visible.
Search Nedrilad ::

Custom Search