How do I load an AudioClip from code?

I wish to load a new AudioClip at runtime. The file, let’s say “sound.mp3”, is stored somewhere on my computer, say “C:\Users\Me\Desktop”. I realize that one can bring a file into the editor and use Resources.Load() from there. However, one cannot add in new files once it’s compiled, so I would like to just do something along the lines of

AudioClip clip = new AudioClip("C:\Users\Me\Desktop\sound.mp3");

Thanks!

Hi,

A good place to start would be:
http://docs.unity3d.com/Documentation/ScriptReference/WWW.GetAudioClip.html

Also if you want to save yourself time check this out (I have used this and it saved a lot of time):

http://u3d.as/content/starscene-software/uni-file-browser/1th

Good luck!

Paul

Using an Audio Source as mentioned here : Unity - Scripting API: AudioSource

Also, here is a Video Tutorial on playing sounds .

Also, I found some example code here:

var audioVolume = 1.0;
var collisionSoundEffect : AudioClip;

function playSound(){

Debug.Log("Animation event called");

audio.volume = audioVolume;

audio.clip = collisionSoundEffect;

audio.Play();

}

Also, for loading from PC etc: http://forum.unity3d.com/threads/102934-Play-a-sound-effect-with-code

PS: Thsi is not mine, and I don’t claim to own the code . I found it here on the Unity forums, and it works .