Hey,
Is there a way of calling a sound file straight from the code instead of setting a variable first (var theSound : AudioClip;)?
I’m working on a game with people remotely so trying to make things easier to intergrate together.
Thanks a lot.
You can load files using Resources.Load - but all files must be inside the Assets/Resources folder (or subfolders):
function PlayFile(file: String){ // file name without extension
var clip: AudioClip = Resources.Load(file);
// example 1: play with PlayOneShot
audio.PlayOneShot(clip);
// example 2: play without an AudioSource component
AudioSource.PlayClipAtPoint(clip, transform.position);
// example 3: play with Play
audio.clip = clip;
audio.Play();
}
...
PlayFile("Explosion"); // play sound file Explosion.wav or Explosion.mp3 etc.
...