public virtual RecycledSound PlayClip(int id, Vector3 pos = new Vector3(), bool unique = false, float volume = 1f, bool selfDestruct = true, bool loop = false) { if (id >= audioClips.Length) { return(null); } var clip = audioClips[id]; var sRef = "Audio: " + clip.name; if (unique) { if (GameObject.Find(sRef)) { return(null); } } var recycledSound = GameObjectUtil.Instantiate(soundTemplate, pos); recycledSound.name = sRef; var source = recycledSound.GetComponent <RecycledSound>(); source.clip = clip; source.volume = volume; source.mute = mute; source.loop = loop; source.selfDestruct = selfDestruct; source.Play(); return(source); }
private void Start() { for (var i = 0; i < populateSoundObjectPool; i++) { var instance = GameObjectUtil.Instantiate(soundTemplate, new Vector3()); instance.GetComponent <RecycleGameObject>().Shutdown(); } }