UPDATED WITH COMPLETE SOLUTION:
In order to get a sound to play on a mouse click, the simplest solution is located here:
http://answers.unity3d.com/questions/857810/play-audio-from-46-ui-button-on-click-script.html
This will get your button sound working. I had to add a delay scene change because the sound latency was so high that the sound would not play in time (the scene changed too quickly.) This code explains how to do that:
private AudioSource audioSource;
private float audioTimer;
public void LoadLevel(string name)
{
StartCoroutine(LoadLevelTimer(audioTimer, name));
}
public void Next(string name)
{
StartCoroutine(LoadLevelTimer(audioTimer, name));
}
void Start()
{
audioSource = this.GetComponent<AudioSource>();
audioTimer = audioSource.clip.length;
}
IEnumerator LoadLevelTimer(float audioTimer, string name)
{
yield return new WaitForSeconds(audioTimer);
SceneManager.LoadScene(name);
}
Finally, I had to change an Audio Setting under Edit > Project Settings > Audio: Set DSP Buffer Size to full performance. This caused the audio to play without delay. If you want to play the audio on a mouse click (any mouse click), this code will suffice:
private AudioSource audioSource;
void Start()
{
audioSource = this.GetComponent<AudioSource>();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
audioSource.Play();
}
Below is the original post:
I have created a new scene called Menu and added a Start Button to it that the user clicks to move into the actual game for my version of Text101. However, every tutorial and attempt I have made to play a sound on the button click has failed. These include the tutorials in the following places (EDIT: deleted two links, left the correct link):
None play the sound when the button is clicked. Is it possible the sound is not playing before the scene changes?
EDIT: Discovered that the last link offers the correct solution. However my button sound would not play because the scene would change too quickly. See below.