I’m trying to make a rhythm game which allows for creation of custom levels. To accomplish this, I need to be able to load audio files from local folders. I can’t use the Resources folder because the user needs to be able to provide the song file themselves during level development.
I’ve been using the following method:
string songPath = "C:\Users\...\levels\[level name]\song.ogg"
using (var www = new WWW("file:///" + songPath))
{
yield return www;
song = www.GetAudioClip();
}
audioSource.clip = song;
It’s been working well, but the console gives me a warning saying that WWW is obsolete, and I should be using UnityWebRequests. I’d like to, to futureproof my game, but I can’t figure out how to do it.
How can I use UnityWebRequests to extract an AudioClip from a local audio file?