Game Development Reference
In-Depth Information
especially if the function is fired a lot since we don't want Unity spending
a lot of processor cycles just finding stuff. But since this particular function
fires only once, it's just as expensive to put it here as it is to further clutter
the function Awake or function Start areas of the code.
After we declare the keyIcon variable and populate it, we use iTween's
MoveTo to slide it onto the screen. Finally, after we declare and populate
keyGeometry, we turn it off. So in the game, if the player mouses over the
key it highlights. Then, if the user clicks the key, the keyIcon slides in and
the geometry of the key disappears.
Finally—and this is important—we tell Unity to keep track and know
that now we have acquired the key and to set the Boolean keyAcquired
to true. We'll need Unity to know this later when we want to open a door
with the key.
Step 9: Save and return to Unity. Fix any syntax errors.
Step 10: To test, temporarily deactivate Hallway_Unbaked and
activate Hallway_BakedGroup (deactivate and activate children when
prompted).
Why?
Remember that we're cheating a little bit. The Key and LockBox don't
even exist in the unlit version (Hallway_Unbaked), but become extant
when the power switch is thrown and the Hallway_BakedGroup comes
online.
Step 11: Play and test.
Creating a Smart Trigger
So now Unity is able to identify if the ray coming from the camera strikes the
key (if it does, the key highlights). If the user clicks the mouse while the ray is
on the key, the geometry of the key disappears and the key icon appears on
the screen. Importantly, Unity also knows that the player has acquired the key.
Now we need to make the door that this key opens have a trigger that checks
to see if the character has indeed acquired the key.
Step 12: For the locked door, we need the baked version of the level.
Deactivate Hallway_Unbaked and reactivate Hallway_BakedGroup (and
their children).
Step 13: Find Hallway_Door_Bulkhead_Group 1. This should be in the
large room with the rust-colored walls if you're using the assets provided
( Figure 16.7 ).
Search WWH ::




Custom Search