public void setAudioActive(bool value) { if (!gameObject.activeInHierarchy) return; if (value) { if (soundPoolObj == null) { soundPoolObj = pool.alloc(transform); if (soundPoolObj != null) soundPoolObj.source.UnPause(); tauntCoroutine = taunt(); if (detatchCoroutine != null) StopCoroutine(detatchCoroutine); StartCoroutine(tauntCoroutine); } } else { if (soundPoolObj != null) { if (!soundPoolObj.source.isPlaying) { soundPoolObj.detatch(); soundPoolObj = null; } else { detatchCoroutine = detatch(); StartCoroutine(detatchCoroutine); } if (tauntCoroutine != null) StopCoroutine(tauntCoroutine); } } }
IEnumerator detatch() { if (soundPoolObj != null) { var source = soundPoolObj.source; while (source.isPlaying) { yield return null; } } if (soundPoolObj != null) { soundPoolObj.detatch(); soundPoolObj = null; } }