Game Development Reference
In-Depth Information
Why?
The iTween.MoveTo should look familiar. After checking to see if
inventoryVisible is true, the iTween line is saying, “take the inventoryPrompt
GameObject, and move it to the coordinates (0,1,0), and do it over 1 second.”
Also take the gameObject this script is attached to and move it to the
coordinates (-.5,1,0). If inventoryVisible is not true then slide inventoryPrompt
to coordinate (0,1.1, 0). Then, take the gameObject this script is attached
to and move it to (0,1,0). Remember that 0,1,0 for a GUITexture means that it
is aligned in the top-left corner of the interface (visible in this case), but that at
0,1.1,0 the GUITexture is slid off the top left of the screen and at (-.5,1,0),
the GUITexture is slid off the left of the screen. So what's happening here
is the prompt slides up as the buttons slide in to make inventoryVisible
true, and the other way around to make inventoryVisible false.
In each block, notice that after the animations are called, we then
define whether inventoryVisible is true or not ( inventoryVisible =
false ;), then we lock or free the cursor ( Screen.lockCursor =
true ;) and finally turn on or off the MouseLook scripts attached to
both the Main Camera and FPC_AegisChung object ( mainCamera
.GetComponent(“MouseLook”).enabled = false ; and fpcAegis
.GetComponent(“MouseLook”).enabled = false; ).
Warnings and Pitfalls
There can be a bit
of confusion about
whether or not the
lockCursor is working
when dealing with the
editor environment. Make
sure that when testing
something that locks the
cursor, that the cursor
is indeed in the Game
window when the game
starts. Then, also realize
that as the mouse is
moved around within the
game, it could be escaping
and actually be invisible
on some other part of the
Unity interface. So when
the mouse is clicked, Unity
could be thinking you're
clicking something in the
Hierarchy, or elsewhere.
If this happens, just
guide the mouse back to
the game window and
click again to tell Unity,
“Yeah, I'm working in
this window, and I want
the mouse click to
register here.”
Step 64: Save and return to Unity. Check for syntax problems.
Step 65: Apply this new InventoryToggle script to InventoryButton_Tab
in the Hierarchy. Apply this addition to the prefab by clicking the Prefab
Apply button.
Step 66: Play and test. The inventory system should be all set up and
running.
Step 67: Save Scene-EntryWay.
Step 68: Open Scene-Hallway.
Step 69: Delete the existing Crosshairs GUITexture from the Hierarchy.
Why?
Remember that now the Crosshairs are part of the GUIElements prefab
we've constructed. And since we don't want or need to, we need to get
rid of one before bringing in the GUIElements prefab.
Step 70: Place the GUIElements prefab in the scene. Do this by dragging it
from the Project panel to the Hierarchy. Make sure its Transform XYZ are all 0.
Why?
Remember that the GUIElements includes our screen hints mechanism
as well as our Crosshairs, and most importantly, our Inventory system.
Bringing it in as a prefab makes everything work for us.
Search WWH ::




Custom Search