Game Development Reference
In-Depth Information
Warnings and Pitfalls
If, for some reason
an extra GUIElement
appears in the Hierarchy
when doing this step, be
sure to delete one. This
happened to me while
writing this step, but I
was unable to get it to
repeat. In either case, we
only need one copy of it.
Why?
This populates the prefab we just created and makes the GUIElements in
the Hierarchy tied to this new prefab.
Animate the Inventory to Show and Hide
So we've got a great collection of GUIElements that we can reuse again
(and will in the Hallway). But we still need to solve the problem of the
mouse problems and always having the inventory visible. To fix this, we'll
create a new script and get a few scripts to do a bit of talking to each other.
Step 55: Create a new JavaScript. Name it InventoryToggle . Open
InventoryToggle.
Step 56: Create three new private variables to hold the Inventory Prompt, the
Main Camera, and the FPC_AegisChung (the First Person Controller prefab):
private var inventoryPrompt : GameObject;
private var mainCamera : GameObject;
private var fpcAegis : GameObject;
Why?
The inventoryPrompt will need to be hidden when the buttons are out
so we need access to it. The Main Camera and FPC_AegisChung both
have attached to them a special script called Mouse Look that makes
the character/camera rotate around based upon the mouse moving.
We'll need to disable these when working with the inventory so we need
access to both.
Step 57: On the game start, have Unity populate these variables:
function Start(){
inventoryPrompt = GameObject.Find("InventoryPrompt");
mainCamera = GameObject.Find("Main Camera");
fpcAegis = GameObject.Find("FPC_AegisChung");
}
Why?
Assuming we don't rename these elements, this is a quick way to make
sure Unity has access to the elements it needs.
Step 58: Establish a Boolean that defines whether or not the inventory is
visible. Add the following line to the variable declarations:
private var inventoryPrompt : GameObject;
private var mainCamera : GameObject;
private var fpcAegis : GameObject;
private var inventoryVisible : boolean;
Search WWH ::




Custom Search