Search Unity

Changing music track after one has stopped issue

Discussion in 'Audio & Video' started by zoogy1983, Jun 20, 2015.

  1. zoogy1983

    zoogy1983

    Joined:
    Apr 28, 2015
    Posts:
    1
    Hey guys. I am having a small issue. I am using Unity 5 and want to have one music track loop after the first one stops. I play the 1st track on awake. Then in my playmusic method I simply have a for loop that goes through my audio sources

    Code (CSharp):
    1. public void PlayMusic(string audioClipName)
    2.     {
    3.         for (int i = 0; i < audioSources.Count; i++)
    4.         {
    5.             if (audioSources[i].clip.name == audioClipName)
    6.             {
    7.                 audioSources[i].Play();
    8.             }
    9.             else
    10.             {
    11.                 if (audioSources[i].isPlaying)
    12.                 {
    13.                     audioSources[i].Stop();
    14.                 }
    15.             }
    16.         }
    In my Update I have a case statement and during the gameplay scene I have:

    Code (CSharp):
    1. if (!GamePlayMusicOne.isPlaying)
    2.                     {
    3.                         PlayMusic("GameplayMusicTwo");
    4.                         Debug.Log("Music two");
    5.                     }
    6.                     break;
    When I put a breakpoint in my if statement and step through ti goes to my playmusic method and actually starts playing the track.. When I am play test this the second track never starts. Very confused.