public void PlayCustomSound(string clip, Vector3 soundPos, string entityToFollow, float volume, bool useGroup) { // Get correct audio clip to play AudioClip clipToPlay = null; if (useGroup) { clipToPlay = soundLibrary.GetGroupClip(clip); } else { clipToPlay = soundLibrary.GetClip(clip); } if (clipToPlay == null) { return; } // Setup sound game object GameObject newSFXSource = new GameObject("SFX2D source"); AudioSource newAudioSource = newSFXSource.AddComponent <AudioSource> (); newSFXSource.transform.parent = transform; // Sound volume settings newAudioSource.maxDistance = 30; newAudioSource.spatialBlend = .96f; // Play audio and destroy it after X amount of time newAudioSource.PlayOneShot(clipToPlay, masterVolume * sfxVolume * volume * volume); StartCoroutine(DestroyCustomSFXSource(newSFXSource)); }
void AssignSoundToSource(SoundLibrary soundLib, AudioSource source) { source.clip = soundLib.GetClip(); source.volume = soundLib.volume; source.pitch = soundLib.pitch; source.loop = soundLib.loop; source.outputAudioMixerGroup = soundLib.mixerGroup ? soundLib.mixerGroup : defaultAudioMixerGroup; }
public void PlaySound(string clipName, Vector3 pos) { AudioSource.PlayClipAtPoint(library.GetClip(clipName), pos, sfxVolume * masterVolume); }
public void PlaySound(string SoundName, Vector3 Position) { PlaySound(Library.GetClip(SoundName), Position); }