public static void PlayClip(AudioClip clip, Vector3 worldPosition, float volume, float pitch) { GameObject gameObject = new GameObject("AudioOneShotObject"); AudioOneShot audioOneShot = gameObject.AddComponent <AudioOneShot>() as AudioOneShot; audioOneShot.PlayClipInternal(clip, worldPosition, volume, pitch); }
protected override void Awake() { base.Awake(); // BGM var bgmSources = new AudioSource[BGM_LINE_MAX]; for (int i = 0; i < bgmSources.Length; i++) { bgmSources[i] = bgmParent.AddComponent <AudioSource>(); } bgmAudio = new AudioLoop(bgmSources); // SE var seSources = new AudioSource[SE_LINE_MAX]; for (int i = 0; i < seSources.Length; i++) { seSources[i] = seParent.AddComponent <AudioSource>(); } seAudio = new AudioOneShot(seSources); // Voice var voiceSources = new AudioSource[VOICE_LINE_MAX]; for (int i = 0; i < voiceSources.Length; i++) { voiceSources[i] = voiceParent.AddComponent <AudioSource>(); } voiceAudio = new AudioOneShot(voiceSources); }
public void PlayAt(Vector3 worldPosition, float volume) { if (Time.time < NextAllowedPlayTime) { return; } int clipIndex = Mathf.FloorToInt(Random.Range(0.0f, (float)(_audioClips.Count - 1))); // TODO: handle distance // AudioListener al = GetCurrentAudioListener(); // looks like this can't be done with PlayClipAtPoint AudioOneShot.PlayClip(_audioClips[clipIndex], worldPosition, volume * _volumeScale, Random.Range(_minPitch, _maxPitch)); #if AUDIO_MANAGER_DEBUG Debug.Log(Time.time + "SoundGroup.PlayAt( '" + _audioClips[clipIndex].name + "', " + worldPosition.x + ", " + worldPosition.y + ", " + worldPosition.z + " );"); #endif NextAllowedPlayTime = Time.time + _throttleTime; }