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
. . .
else
{
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);
if(hit.gameObject.name == "RedKey")
{
Camera.main.GetComponent("gui").theRedKey = hit.
gameObject;
}
else if(hit.gameObject.name == "GreenKey")
{
Camera.main.GetComponent("gui").theGreenKey = hit.
gameObject;
}
}
. . .
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