void Awake(){ if(instance!=null){ Destroy(gameObject); return; } instance=this; thisObj=gameObject; thisT=transform; DontDestroyOnLoad(thisObj); audioSourceList=new List<AudioSource>(); for(int i=0; i<10; i++){ GameObject obj=new GameObject(); obj.name="AudioSource"+(i+1); AudioSource src=obj.AddComponent<AudioSource>(); src.playOnAwake=false; src.loop=false; obj.transform.parent=thisT; obj.transform.localPosition=Vector3.zero; audioSourceList.Add(src); } AudioListener.volume=sfxVolume; }
void Awake(){ if(instance!=null){ Destroy(gameObject); return; } instance=this; thisObj=gameObject; thisT=transform; DontDestroyOnLoad(thisObj); if(playMusic && musicList!=null && musicList.Count>0){ musicSource=thisObj.AddComponent<AudioSource>(); musicSource.loop=false; musicSource.playOnAwake=false; musicSource.volume=musicVolume; musicSource.ignoreListenerVolume=true; if(shuffle) currentTrackID=Random.Range(0, musicList.Count); musicSource.clip=musicList[currentTrackID]; musicSource.Play(); } audioSourceList=new List<AudioSource>(); for(int i=0; i<10; i++){ GameObject obj=new GameObject(); obj.name="AudioSource"+(i+1); AudioSource src=obj.AddComponent<AudioSource>(); src.playOnAwake=false; src.loop=false; obj.transform.parent=thisT; obj.transform.localPosition=Vector3.zero; audioSourceList.Add(src); } AudioListener.volume=sfxVolume; }