Game Development Reference
In-Depth Information
Listing 6.12 Making a Previously Held Game Object Invisible after
Picking up Another Item
. . .
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;
}
}
//---REMOVE OR COMMENT OUT LINES BELOW TO KEEP HOLD OF
//OBJECT
//release the previously held game object
//currentObj.transform.parent = null;
//currentObj.AddComponent(BoxCollider);
//make object invisible
currentObj.renderer.enabled = false;
//set currentObj to the new object - just picked up
currentObj = hit.gameObject;
. . .
Step 30. We need to provide a way for the player to cycle through
held items. Using Doom as a model, we will use the keyboard
keys 1 through 5. Modify gui.js to accept player input as shown in
Listing 6.13 .
Listing 6.13 Script to Make Inventory Items Visible When
Associated Keys Are Pressed
var redkey : Texture2D;
. . .
function OnGUI ()
{
. . .
}
function ResetKeys()
{
Search Nedrilad ::




Custom Search