Game Development Reference
In-Depth Information
If you've done all of the above, you're i nished! Now go reward yourself
by starting up Game Mode and playing your Scene. Move your
character into the Door and you should dei nitely hear a satisfying
sound ef ect.
Help! I Can't Trigger the Sound
If you experience errors in compiling or anything else, ask yourself the
following questions:
1. Is your code completely accurate? It has to be exactly as detailed
earlier. If it's missing one character, such as a curly bracket, it can fail
compilation and you won't be able to run your Scene.
2. Did you drag an AudioClip to the script variable? In this case you
don't want to drag an AudioClip to the heading in the Audio Source
Component because the method PlayOneShot requires a variable.
So make sure you drag it instead over the Sound variable in the Script
Component, not the Audio Source.
Trigger Dilemmas
So one thing that you might notice is that any object that you turn
into a trigger automatically becomes transparent to whatever objects
are passing through. This may not be the most desirable situation—
for example, if you were to run into a Door you would not want to
necessarily pass through the Door in order for the sound to play, but
rather to literally collide with it. How would you do that? There are a lot
of options at your disposal—coming strictly from a position involving
only triggers, what you would
do would be to create another
object just in front but make it
invisible. That way when you
encounter the invisible trigger
the sound will play and then
you can take the trigger option
on the Door object of , so that
it behaves more like a real door
would.
Fortunately a lot of this work is already done for you. Notice that the
game object Door has a triangle next to it. Click the triangle to expose
the object underneath it. It's called Door Trigger , and as you can see
it's currently grayed out. This is because the game object has been
deactivated. To activate and deactivate a game object click on it in the
 
Search WWH ::




Custom Search