play audio by filename

I have some sound files in my project with names like like “loop red 5”. How can I play these just once by that name?

Make sure your audio files are in a folder named “Resources” in your root directory of the project and use

AudioClip clip = (AudioClip)Resources.Load("audio/loop red 5");
audio.PlayOneShot(clip);

This assumes that the file is in ‘Resources/audio/’ and that the game object you are attaching it to has an AudioSource attached to it. Also, this is in C#. I don’t know what language you are programming in, but the logic will remain the same.

1 Like

That worked, thanks!