public AudioSourceController Play(Vector3 position) { controller = AudioPoolManager.Instance.GetController(); float volGen = AudioUtils.DecibelToLinear(Volume + Random.Range(RandomVolume, 0)); float pitchVar = (RandomPitch / 2); float pitchGen = AudioUtils.St2pitch(Random.Range(Pitch - pitchVar, Pitch + pitchVar)); controller.SetSourceProperties(GetClip(), volGen, pitchGen, Loop, SpatialBlend); controller.SetPosition(position); controller.Play(); return(controller); }
// Returns length of random clip just played private float PlayRandomClip(SFXScriptableObject sfxSO, Vector3 pos) { asc = GetController(); var audioClipArraySize = sfxSO.audioClips.Length; if (audioClipArraySize == 0) { Debug.LogError("Please set audio clip(s) on " + sfxSO.name + " scriptable object."); return(0); } AudioClip clip = sfxSO.audioClips[Random.Range(0, audioClipArraySize)]; if (asc != null) { asc.SetPosition(pos); asc.SetSourceProperties(clip, sfxSO.volume, sfxSO.pitch, sfxSO.loop); asc.Play(); } return(clip.length); }