Game Development Reference
In-Depth Information
hit.gameObject.transform.parent = attachPoint.
. . .
Step 18. Play. The door will only open when the player walks up to it
holding the RedKey object.
At the moment it is obvious which object the character is holding
because it is visible in its hand. However, should the character be able
to carry multiple objects, they won't all be visible in the 3D environment
all of the time. Therefore, a graphical interface will be created to indicate
which items the character has picked up.
Step 19. Create a new JavaScript file called gui and add the code
shown in Listing 6.9 .
Listing 6.9 A Simple GUI Indicating Inventory Items
var redkey : Texture2D;
var bluekey : Texture2D;
var yellowkey : Texture2D;
var greenkey : Texture2D;
var greykey : Texture2D;
var theRedKey: GameObject;
var theBlueKey: GameObject;
var theYellowKey: GameObject;
var theGreenKey: GameObject;
var theWrench: GameObject;
function OnGUI ()
GUI.BeginGroup (Rect (Screen.width/2.0 - 120,
Screen.height - 80, Screen.width,
GUI.Box (Rect (0,0,240,80), "");
GUI.Box (Rect (3,3,75,75),"Health");
GUI.Box (Rect (83,3,75,75),"Pic");
//keys in inventory
GUI.Box (Rect (160,3,35,35), redkey);
GUI.Box (Rect (160,3,35,35), greykey);
GUI.Box (Rect (200,3,35,35), bluekey);
GUI.Box (Rect (200,3,35,35), greykey);
Search Nedrilad ::

Custom Search