Playing audio when a button is clicked?

I am currently using Unity Javascript and am trying to get an audio clip to play when I click on a button for the main menu. I have background music, so I figured I could put a second audio source on the main camera (where the GUI and audio is located for me) and write some line of code within an if block for the button. However, I do not currently know of a way to play that sound, I know it has something to do with either AudioSource or AudioClip. (I am a new programmer if you can’t tell) What would need to be used to get this audio file to play when clicked?

Hi,

you can add the following to you script.

this.GetComponent(AudioSource).Play();

You will need to add an AudioSource component with the sound you want to play in it.

Hope this helps.