Search Unity

Audio AudioSource file.Play() does not play the file

Discussion in 'Audio & Video' started by DuraniRobben, Jul 13, 2018.

  1. DuraniRobben

    DuraniRobben

    Joined:
    Apr 23, 2018
    Posts:
    3
    I have a few AudioSources of which one is the background music for my Scene.
    When the character dies/wins I wanted to stop the background music and play an appropriate audio.
    I do this like this:
    Code (CSharp):
    1. loseSound.volume = ambientSound.volume;
    2. ambientSound.volume = 0;
    3. ambientSound.Stop();
    4. loseSound.Play();
    But no sound is played. The ambientsound stops but the other doesnt start.

    Thanks in advance for any help.
     
  2. Docaroo

    Docaroo

    Joined:
    Nov 7, 2017
    Posts:
    82
    We'll need to see a bit more code than that ... how are ambientSound and loseSound defined? What objects are they referring to? Are they definitely assigned to the correct (and 2 different) audiosources?