void Awake() { // Destroy duplicate of this instance if (instance != null) { Destroy(gameObject); } else { instance = this; DontDestroyOnLoad(gameObject); sfxLibrary = GetComponent <SfxLibrary> (); musicSources = new AudioSource[2]; for (int i = 0; i < 2; i++) { GameObject newMusicSource = new GameObject("Music source " + (i + 1)); musicSources [i] = newMusicSource.AddComponent <AudioSource> (); musicSources [i].loop = true; newMusicSource.transform.parent = transform; } // Use to play sfx GameObject newSfx2Dsource = new GameObject("2D sfx source"); sfx2DSource = newSfx2Dsource.AddComponent <AudioSource> (); newSfx2Dsource.transform.parent = transform; // Save Master / Music / Sfx value to ...vol (if it's exist) or 1 as default masterVolumePercent = PlayerPrefs.GetFloat("master vol", 1); sfxVolumePercent = PlayerPrefs.GetFloat("sfx vol", 1); musicVolumePercent = PlayerPrefs.GetFloat("music vol", 1); PlayerPrefs.Save(); } }
public override void Start() { //base.Start (); myRadius = 1.4f; worldObj = FindObjectOfType <World> (); GameOver.instance.OnGameOver += OnGameOver; lib = FindObjectOfType <SfxLibrary> (); }
void Init() { sfxLibrary = GetComponent <SfxLibrary> (); // Initialize sound effect pool sfxSourcePool = new AudioSource[sfxPoolSize]; sfxTimesRemaining = new float[sfxPoolSize]; sfxPoolIndexQueue = new List <int>(); for (int i = 0; i < sfxPoolSize; i++) { AudioSource newSfx = Instantiate(sfxSource) as AudioSource; sfxSourcePool[i] = newSfx; sfxSourcePool[i].transform.parent = transform; sfxPoolIndexQueue.Add(i); } // Retrieve saved audio levels SetDefaultVolume(Channel.Master, PlayerPrefs.GetFloat("masterVolumePercent", defaultMasterVolumePercent)); SetDefaultVolume(Channel.Music, PlayerPrefs.GetFloat("musicVolumePercent", defaultMusicVolumePercent)); SetDefaultVolume(Channel.Sfx, PlayerPrefs.GetFloat("sfxVolumePercent", defaultSfxVolumePercent)); }