public void Stop(float fadeTime = 0f) { StopAllCoroutines(); if (fadeTime > 0) { SetVolumeTo(0f, fadeTime, delegate() { CachedAudioSource.Stop(); CachedAudioSource.clip = null; }); } else { CachedAudioSource.Stop(); CachedAudioSource.clip = null; } isPlaying = false; StopEvent(this); //TODO get recycling of sounds working Destroy(gameObject); //ObjectPool.Recycle(gameObject); }
public void Play(Sound sound, float fadeTime = 0f) { StopAllCoroutines(); CachedAudioSource.Stop(); CurrentSound = sound; Volume = fadeTime == 0f ? VolumeFromSettings : 0f; CachedAudioSource.clip = sound.audioClip; CachedAudioSource.loop = sound.loop; CachedAudioSource.pitch = Random.Range(sound.minPitch, sound.maxPitch); CachedAudioSource.spatialBlend = sound.spatialBlend; CachedAudioSource.volume = sound.volume; CachedAudioSource.loop = sound.loop; CachedAudioSource.Play(); //TODO dont relly on this CachedAudioSource.spatialBlend = 0; if (fadeTime > 0f) { SetVolumeTo(VolumeFromSettings, fadeTime); } isPlaying = true; PlayEvent(this); }