Lab 10 - Sound editing and integration
In this lab, you will learn how to edit sounds in Audacity and integrate them into your game. As your homework, you have to find and edit sounds for three actions in your project game. Each team member has to do it individually, so at the end of this lab, you will have collectively made 9 sounds for your game. Discuss it with your teammates to make sure that everyone is searching sounds for different actions.
Sound editing steps:
- Go to freesounds.org and register an account if you don't have one yet.
- Find a suitable sound file for your game. The sound should be relatively short max 3 seconds (eg. click, hit, punch etc.) but the sound file can be much longer so you can cut it.
- Find a similar sound that can be used for variation. If your original sound file already contained multiple repeats then you can use these instead.
- Open your sound file in Audacity, trim it to the correct length. Remove any delay from the beginning (the sound has to start immediately).
- Apply necessary effects, for example, fade-in/fade-out if it contains noise.
- Export your audio in an OGG file.
Integrating sounds in Unity steps:
- Create a new empty project, add your sound files.
- Create 3 new scripts:
- Game.cs - plays different sounds when the number buttons are pressed
- AudioSourcePool.cs - allows to get audio sources and reuse the old ones.
- AudioClipGroup.cs - a scriptable object that defines a group of similar audio file.
- Implement AudioSourcePool:
- Add a private list of audio sources. Initialize this list in your Awake method.
- Add a new method GetSource that returns an AudioSource. This method should loop through the audio source list and return the first AudioSource that isn't playing anymore. If such AudioSource doesn't exist it should make one and return it instead, don't forget to add it to the list as well.
- Implement AudioClipGroup:
- Make it a scriptable object and add [CreateAssetMenu(menuName = "AudioClipGroup")] attribute.
- Define public variables for VolumeMin, VolumeMax, PitchMin, PitchMax, Cooldown and a list of AudioClips. Use [Range(0, 2)] attribute for your float fields.
- Define private variables for timestamp and audioSourcePool reference;
- In the OnEnable method, zero the timestamp and find your AudioSourcePool reference.
- Add a public void Play(AudioSource), check if the cooldown has passed and then initialize the source clip, volume, and pitch according to the data. Finally, play the audio source.
- Add a public void Play(), find a free audio source from your pool and call the other play method with your audio source.
- (extra) Add a public void Play(Vector3 location) and make it play a location-based audio.
Finally, search and edit sounds for two more actions in your game and make your Game script to play these sounds groups when number keys are pressed.
Build and submit your sound preview project. It doesn't have to show anything but has to play first sound group when the user presses number 1, second sound group when the user presses 2 and third sound group when the user presses 3.
At least 2 sound groups have to contain at least 2 variations of a similar sound. At least one sound group has to randomly change the pitch as well.