Game Development Reference
In-Depth Information
Step 22. There are also five pickup objects at the top of the script,
which will hold onto the wrench and keys that have been picked
up. When a game object exists, the associated colored key icon will
appear in the GUI.
Step 23. Open pickup.js and edit the code as shown in Listing 6.10
to cause the red key icon to turn on when the character picks up
the red key.
Step 24. The new script will set the haveRedKey Boolean value in the
gui.js script to a value of true when the RedKey is picked up. This will
cause the GUI to display the red key icon in place of the grayed out
one. Play to test it.
Listing 6.10 Setting a Boolean Value for the Inventory
var attachPoint: GameObject;
private var currentObj: GameObject;
. . .
function OnControllerColliderHit (hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "door")
{
. . .
}
else if(hit.gameObject.tag == "key")
{
. . .
if(hit.gameObject.name == "wrench")
{
. . .
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;
}
. . .
Search Nedrilad ::




Custom Search