-
Book Overview & Buying
-
Table Of Contents
Mastering Unity 2D Game Development - Second Edition
By :
We will create another AudioSource to play all sound effects. The way in which we have the sound effect play will be handled through code instead of having it play instantly and continuously.
Now, within the Hierarchy, select Create | Audio | Audio Source. Position it at 0,0,0 and rename it Sound, as shown in the following screenshot. Since we don't want a sound to play the moment the game starts, deselect Play On Awake. Also drag and drop the KeepAround.cs script into the Inspector:

I chose to have this single audio source for my sound effects and to have it continue through each scene to make muting and unmuting the sound easier.
To easily access the Sound GameObject through code, we will use a Tag. Select the Sound GameObject and add the new tag Sound. As shown in the following screenshot:

We can add all sorts of sounds to our game and the process will be the same throughout. For this text, to preserve the page count, we will only...
Change the font size
Change margin width
Change background colour