Search Unity

Play music from desktop

Discussion in 'Scripting' started by Kirby26, Oct 20, 2019.

  1. Kirby26

    Kirby26

    Joined:
    Mar 3, 2019
    Posts:
    13
    Hi. Im making a system in what you put !play "name of the song" "if its looped" who load the file and play it in the game for you.

    this is a Ienumerator.
    Code (CSharp):
    1. string Rute = System.IO.Directory.GetCurrentDirectory() + "/Example/Music/";
    2.        
    3.             WWW GetSong = new WWW(Rute+NameFile+".wav");
    4.  
    5.        
    6.             yield return GetSong;
    7.         if (_clip != null)
    8.         {
    9.             _clip.clip = GetSong.GetAudioClip(false, true);
    10.             if (loop == "1")
    11.             {
    12.                 _clip.loop = true;
    13.             }
    14.             else
    15.             {
    16.                 _clip.loop = false;
    17.             }
    18.  
    19.         }
    I think im failing in what code im should be using. Maybe isnt the correct way to load a file from your computer. If anyone can help me in how to load a audiofile from desktop, not the editor, a path in your computer. Im going to be so happy.