Basic Game Audio Implementation using Unity
Here I have two different audio files that I implemented into the game. These clips were intended to serve as background music and laser fire audio. The First implemented audio clips was the background wherein I decided to make use of an Audio_Manager gameObject.
The Implementation is relatively simple. After the Game Object were added to the hierarchy the only remaining task was to add a Audio Source component to the Background Object to indicate that audio pertains to. Then, I was able to simply drag in the audio file to the AudioClip variable and then check the “Play on Awake” and “Loop” boxed. The audio played as intended as soon the game began and looped endlessly.
Next, the laser audio was implemented, but this could not be accomplish in as easy of a way as with the background music. The audio here needs to the created by the player and only at the time wherein a laser is instantiated. First AudioClip and AudioSource Game Objects need to be declared and initialized. Where the AudioClip is an Serialized Field allowing us to drag in the audio file using the Unity user interface.
Now that the audio is initialized the clip can simply be played at time using the Audio Source object’s play method. Here I a play the laser fire sound a affect when the FireLaser method is called.
This is usually the part of the post where I would add a gif or picture to show the result, but that doesn't really work because only audio was implemented. So uh, I guess you are going to have to just imagine that it is working. :)