void Start() { if (BGMusic == null) { DontDestroyOnLoad(gameObject); BGMusic = this; } else if (BGMusic != this) { Destroy(gameObject); } localSoundVolume = TemporaryGameVars.soundVolume * 0.5f; aSource = GetComponent <AudioSource>(); aSource.volume = localSoundVolume; if (TemporaryGameVars.mutedVolume == 1) { muteAudio = true; aSource.mute = true; } else if (TemporaryGameVars.mutedVolume == 0) { muteAudio = false; aSource.mute = false; } }
public Canvas menuCanvas; //Reference to the menuCanvas( the canvas that pops up when M or Menu is pressed(has a mute button)) // Use this for initialization void Start() { //Setup a Singleton Like Object if (BGMusic == null) { DontDestroyOnLoad(gameObject); BGMusic = this; } //and make sure it persists //if another is found.. destroy so only one exists. else if (BGMusic != this) { Destroy(gameObject); } //set localSoundVol to that of half of the Static soundVolume localSoundVolume = TemporaryGameVars.soundVolume * 0.5f; //get audio source from this object aSource = GetComponent <AudioSource>(); //set audio source volume to the new localSoundVolume aSource.volume = localSoundVolume; //if we retrieve the PlayerPrefs int and its 1(yes), we set our muted boolean to true, and our mute //property on the audio source to true. if (TemporaryGameVars.mutedVolume == 1) { muteAudio = true; aSource.mute = true; } //else if its 0, we set both to false... this is how we used playerprefs with and int value/ else if (TemporaryGameVars.mutedVolume == 0) { muteAudio = false; aSource.mute = false; } //on game start the menuCanvas should NOT be showing menuCanvas.enabled = false; }