Search Unity

Sound play well in a scene and don't play in another while having the same script

Discussion in 'Scripting' started by SmokyZebra, Mar 30, 2014.

  1. SmokyZebra

    SmokyZebra

    Joined:
    Mar 13, 2014
    Posts:
    139
    Hello.


    I'm not sure it's a script issue because the script do work well in a scene.
    So I have a sound that is supposed to play when i click on a button. I have an audio source and an audio listenner (main camera). The script to play the sound is not on the button but on another GUI object so i have one audiosource for all my buttons. here is the script on the button : Gestionnaire_De_Son_IU.sonAjouer = true;

    and here is the script on the audio controller script (named Gestionnaire_De_Son_IU, i'm french) :

    static var sonAjouer : boolean = false;

    function Update () {

    if(sonAjouer == true){
    if(!audio.isPlaying){
    audio.Play();
    sonAjouer = false;
    }
    }
    }

    So my problem is that i have a scene in wich this device work well and play the sound when i click on the button. The weird thing is that i have another scene with the exact same set up and in wich the sound doesnt work. If i check "Play on awake", the sound do play once but not when i'm clicking on the button. So i know that's not a problem with the audiosource nor audiolistenner. Unity is acting as if this script was not read during runtime I've put Debug.Log the line before audio.Play and it appears, proving that the script is read up to that point at least. Other functions of my button work well in both scenes, just the sound do not work. So if anybody have an idea of what i could forget when i've paste the device from one scene to the other, like an option unchecked or whatever that would be great.
     
  2. SmokyZebra

    SmokyZebra

    Joined:
    Mar 13, 2014
    Posts:
    139
    So if I turn of 3d sound, the sound is working. But i need 3d sounds in my game, so the problem is still there.The weird thing is that the sound work in one of my scene, even with 3d sound on, but not in the other...Please help ! My whole project is stopped because of this sound not playing issue ! :cry:
     
    Last edited: Mar 31, 2014