Hello everybody,
I found the code below on the forums and it works fine when muting music and image sprites change accordingly. The issue is that when I change scenes, though the code remembers mute or unmute state, the sprite reverts back to the source image. Is there something i could change in the code to fix that so it remembers last used sprite state?
Many thanks
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class AudioToggle : MonoBehaviour {
public Sprite spriteMusicOn;
public Sprite spriteMusicOff;
public void ToggleAudio (Image spriteMusicToggle) {
if(AudioListener.volume == 0.0f) {
AudioListener.volume = 1.0f;
spriteMusicToggle.sprite = spriteMusicOn;
}
else if(AudioListener.volume == 1.0f) {
AudioListener.volume = 0.0f;
spriteMusicToggle.sprite = spriteMusicOff;
}
}
}