上QQ阅读APP看书,第一时间看更新
Audio sources and listeners
Before we add audio to our scene, we need to cover a few more basic concepts within Unity.
Of course, the best way to do that is to get hands on and explore more of the scene objects with the following exercise:
- If you have taken a break, open back up Unity and reload the GameAudioBasics project, which we saved at the end of the last section. Of course, if you haven't taken a break, good for you, and just continue as you were.
- Now, divert your attention to the Hierarchy window and specifically the search field at the top of the window. Click on the down arrow at the left of the search field, to select the form of the search as shown in the following screenshot:
Setting the search type
- Now, enter AudioListener; make sure to use the same case in the search field. This will filter the GameObject in the Hierarchy window with an AudioListener component attached, as shown in the following screenshot:
Hierarchy window showing filtered list of game objects with AudioListener
- As you can see, this filtered list of objects is showing us the various scene cameras. A camera in Unity is what captures the rendered view of the scene. As such, you can think of a camera as the player's eyes to the game world. Therefore, it only makes sense that we also make the camera be able to listen to the world using the AudioListener component. That way, as the camera moves around the scene, the ears or Audio Listener, will also be tightly coupled.
A GameObject in Unity is the base scene object. What differentiates one object from another is the components attached to the GameObject. A component is a script that applies specialized functionality to a GameObject. A component could include everything from a camera, audio listener, audio source, mesh renderer, and so much more. The Inspector window allows you to view, modify, add, and remove components on a GameObject.
- Select Camera_high at the top of the list in the Hierarchy window and take a look at the Inspector window and bottom-right corner of the Scene view as shown in the following screenshot:
Camera preview and Inspector window
- As you can see, there are a number of components attached to the Camera_high object in the Inspector window. We won't get into the details of all the components but just take notice of the Camera and Audio Listener. Remember that these two components equate to the scene's eyes and ears. Select the Camera_high object selected and press the Play button to run the scene.
- After the scene starts running and switches to the Game view, press the Esc key to unlock the mouse. Then, go to the Inspector window and scroll through the components. Feel free to turn off and on components by unchecking the checkbox beside the component name. You can even alter the component settings if you like. Notice how the Game view changes as you make those changes. Don't be afraid to change several things; as long as you are in play mode, nothing will be saved.
- When you are done with exploring the Inspector window, press the Play button again to stop the game running.
Good. As you can see, we already have a number of Audio Listener components set up on the scene. This means that we can certainly hear any audio. However, we are still missing the source of our audio, which hasn't been configured. In the next section, we will add an Audio Source component to our scene.