Playing sound when a scene begins
Often, we want a sound to play as soon as a scene is loaded; this may be to indicate to a player that the new scene is ready, or perhaps it’s some background music or audio sound effect for the scene. As you’ll see in this recipe, Unity makes it very easy for us to play as soon as a scene is loaded.
Before we start using the 3D scene created in the first recipe of this chapter, we’ll first explore some core audio features in a 2D project in this recipe.
Getting ready
Try out this recipe using any audio clips you might have on your computer. We have included a number of classic Pacman game sound clips inside the 04_02
folder.
How to do it...
To play a sound when the scene is loaded, perform the following steps:
- Create a new Unity 2D project. There is a single sample scene, containing a
Main Camera
GameObject that has an Audio Listener component. - Import the sound clip files.
- Select the...