To start there is a “beep” while the real audio loads in the background.
1. In the game object put the audio.
2. Put an audio listener too.
3. Reuse the Collision trigger script that played the sound.
4. Extend it to load audio as coprocess.
5. When the audio loads, swap it in.
[script]
public class ClickButton : MonoBehaviour {
bool clicked = false;
public float elapsedTime = 0.0f;
// Use this for initialization
void Start()
{
StartCoroutine(LoadClip());
}
void Update()
{
if (clicked)
{
AudioSource audio = GetComponent
if (!audio.isPlaying)
{
clicked = false;
var tmp = transform.position;
tmp.x += .08f;
transform.position = tmp;
}
}
}
void OnMouseDown()
{
var tmp = transform.position;
if (!clicked)
{
clicked = true;
tmp.x -= .08f;
GetComponent
}
else
{
clicked = false;
tmp.x += .08f;
GetComponent
}
transform.position = tmp;
}
IEnumerator LoadClip()
{
WWW www = new WWW(“http://www.tonycuffe.com/mp3/tail%20toddle.mp3”);
while (!www.isDone)
{
elapsedTime += Time.deltaTime;
yield return null;
}
// TODO – look for errors, try again, etc.
AudioSource audio = GetComponent
audio.clip = www.GetAudioClip(false, false);
yield break;
}
}
[/script]