1

I am trying to create custom radio tracks in my Unity game, and I want the user to be able to place audio files in a directory like My Documents/My Games/Unity Game/Custom Sounds/ . Then I want Unity to put all audio clips from this folder into an array for me to use in my code. I have searched but cannot find anything about loading a file you don't know the exact path of, or how many there will be

Toxxic
  • 57
  • 1
  • 1
  • 6
  • 2
    This is actually a pretty big question, there are several file browsers you can download from the Unity Asset store, or you can build your own. if you are building your own you can start by using the path provided by the Application.PersistentData Path, and using the classes in System.IO for navigation, and getting a list of files in a directory. – AresCaelum Nov 20 '18 at 01:50
  • @Eddge I've got that working, any idea how to turn all found files into audio clips? I'm close but there is no audio, the length of the clip is correct though – Toxxic Nov 20 '18 at 20:21
  • Yes, use the WWW class. https://docs.unity3d.com/ScriptReference/WWW-audioClip.html for the URL use `file://` then the path of the file, it is important to note that unity only supports some music file formats, depending on the platform. So for example .mp3 will not work if building for windows desktop. – AresCaelum Nov 21 '18 at 14:41
  • @Eddge that did it, thanks! – Toxxic Nov 22 '18 at 04:16

1 Answers1

0

From @Eddge:

Yes, use the WWW class. docs.unity3d.com/ScriptReference/WWW-audioClip.html for the URL use file:// then the path of the file, it is important to note that unity only supports some music file formats, depending on the platform. So for example .mp3 will not work if building for windows desktop

Toxxic
  • 57
  • 1
  • 1
  • 6