Game Development Reference
In-Depth Information
the ground. However, in this sort of game, where the player cannot see his
own feet, this sort of exact timing isn't of concern. However, being able to
hear those feet even if they can't be seen will help bring the player in.
To make this happen believably we will need to do just a bit of scripting. No
worries though. Although we won't spend a lot of time explaining the script
right now, after the next couple of chapters you can come back and take a look
at it and it'll be much easier to understand what the script is actually doing.
But before we get into any scripting, we need to create the necessary assets.
Step 15: Create a new Audio Source for the footsteps. First, select the
First Person Controller in the Hierarchy. Move the mouse over the Scene
view, and press F on the keyboard (this will focus on the First Person
Controller GameObject). Choose GameObject>Create Empty. Rename the
GameObject Sound-Footsteps .
Why?
By first focusing on an object, when the empty GameObject is created,
it will be created at the same location as the focused object. This means
this new GameObject (which will contain our Audio Source) is already
positioned correctly on the First Person Controller.
Step 16: Make this Sound-Footsteps a child of First Person Controller. Do this
in the Hierarchy by dragging it on top of First Person Controller. You will be
presented with a warning indicating that doing this will cause the loss of a
“prefab connection.” Go ahead and press the Continue button ( Figure 11.4 ).
Figure 11.4 Losing prefab warning.
Why?
The footsteps are caused by the player's feet. Wherever the character
goes, those footsteps should go with him. By making the source a child
of the First Person Controller, when the footstep audio plays, the Audio
Listener attached to the Main Camera (also a child of the First Person
Controller) will always “hear” it.
Tips and Tricks
Losing prefab connection can be a hassle in some situations. Remember
that when importing an object into Unity, Unity automatically creates a
Search WWH ::




Custom Search