Example #1
0
    //To play clips when something dies (Won't stop playing if the GameObject is destroyed)
    protected AudioSource PlayLingeringSFX(SFX sfx)
    {
        AudioSource tempSource = new GameObject().AddComponent <AudioSource>() as AudioSource;

        tempSource.outputAudioMixerGroup = audioMixerGroup;
        tempSource.gameObject.name       = String.Format("SFX {0}", sfx.GetAudioClip().name);
        tempSource.pitch = sfx.GetPitch();
        tempSource.PlayOneShot(sfx.GetAudioClip(), sfx.GetVolume());

        Destroy(tempSource.gameObject, sfx.GetAudioClip().length);
        return(tempSource);
        // tempSource.GetComponent<AudioSource>();
        // AudioSource.PlayClipAtPoint(sfx.GetAudioClip(), transform.position, sfx.GetVolume());
    }
Example #2
0
 protected void PlaySFX(SFX sfx)
 {
     audioSource.pitch = sfx.GetPitch();
     audioSource.PlayOneShot(sfx.GetAudioClip(), sfx.GetVolume());
 }