Can you hear the explosion, the laser, and the music? No? Well that's because we have no Audio Source! Definitely not because it is a image or anything.
Like everything in Unity, a component is needed for playing a premade Audio Clip. In the case of the background music, I can just put a Audio Source on a Audio Manager, and just have it constantly play the music on a loop.
However, for anything such as a laser shooting and such, we are going to have to go into the code for that.
As always, we first create variables to hold our Audio Clip (The laser sound) and the Audio Source component after a GetComponent.
Then it is as simple as setting our Clip into the audio source.
Then just having it play when we fire our laser! Now this all could technically be set via the Inspector, but best practices and well what if I wanted more audio clips on the Player for different things?
There is a second way to do this, and you can think of it as like Instantiating a Audio Clip to play for that moment. It creates a AudioSource on the spot, and event destroys if for you afterwards. Nifty for certain things as you do not need a AudioSource component on the object!
Now I wont be making a rhythm game anytime soon, but Audio is a key component in any game. Once again Unity makes things quite easy!
See you next post!