Game Development Reference
In-Depth Information
Why?
Measuring distance is actually pretty straightforward and is presented
reasonably clearly in the documentation ( just do a search for
“distance”). There are several ways to measure distance; Vector3
.Distance just means to measure distance in all dimensions. What this
code is doing is saying, “if the Vector3.Distance between the position
of placedEMP and keypadLock is less than or equal to 1, then do the
following things.” The next four lines should be familiar to you by
now—they change the color of keypadLock, activate keypadSmoke,
and then use iTween to rotate open both doors to 45 and -45 degrees,
respectively, over 8 seconds.
Now this has some limitations. It assumes we are only using the EMP to
break open the keypadLock (which we are). But if in an expanded version
of the game the EMPs were going to be used for other objects, we'd need
to include some other mechanism (perhaps additional Booleans) to do
this. But for now, this is going to work out great.
Step 24: Save and return to Unity. Fix syntax problems.
Step 25: Populate the new public variables ( Figure 15.30 ). These should be
populated from objects in the Hierarchy (not the Project panel). If you're
using the Unity packages, the names will largely match. But feel free to
use your own.
Figure 15.30 Populating the new
variables.
Tips and Tricks
As a side note, the EntryWay_KeyPadSmoke ( Figure 15.31 ) is actually just
a slightly modified smoke particle emitter from Unity's built-in Particles
(accessible in the Standard Assets/Particles folder if you've already
imported the Particles Unity Package). Pick one and then put it into the
scene next to the keypad. Make any changes you want to the smoke.
Then use that smoke to populate the Keypad Smoke entry field.
Step 26: Test and play.
Search WWH ::




Custom Search