- Home /
Question by
H3lls7rik3r · Feb 28, 2015 at 10:17 PM ·
buildloadingaudioclipresources
Loading Audioclip from Resources fails in Build
Hey Guys,
I load Audioclips from the Resources folder into an Audioclip-List. In the editor it works fine, but in the Build not... "object reference not set to an ...". It seems like the Audiofiles are missing...
public List music; AudioClip curClip; float curPlayTime;
public void Start () {
LoadMusic();
ShowMenu(CurrentMenu);
curClip = music[Random.Range(0, music.Count - 1)];
audio.PlayOneShot(curClip);
}
void Update () {
PlayMusic();
}
void PlayMusic () {
if(curClip.length < curPlayTime){
curClip = music[Random.Range(0, music.Count - 1)];
audio.PlayOneShot(curClip);
curPlayTime = 0f;
}
curPlayTime += Time.deltaTime;
}
void LoadMusic () {
DirectoryInfo dir = new DirectoryInfo("Assets/Resources/Music");
FileInfo[] info = dir.GetFiles();
foreach (FileInfo f in info){
if(f.Name.EndsWith("mp3")){
string path = f.ToString();
Debug.Log(path);
path = path.Remove(path.Length - 4, 4);
path = path.Remove(0, path.Length - 15);
path = path.Replace("\\", "/");
Debug.Log(path);
music.Add(Resources.Load<AudioClip>(path));
}
}
}
Thanks for the help :)
Comment
Your answer
Follow this Question
Related Questions
How can I include the resources folder to my project and build it to play on android devices? 1 Answer
Distribute terrain in zones 3 Answers
Why doesn't the Web Player load from my website? 2 Answers
Altering prefab at runtime. Works in editor, not in build. 2 Answers
How do I load images after building? 1 Answer