Esempio n. 1
0
 public static AudioSource PlayClipAtPoint(AudioSettings soundSettings, Vector3 pos,
                                           float delay            = 0f,
                                           SoundSourceType source = SoundSourceType.Unknown)
 {
     if (soundSettings != null)
     {
         return(PlayClipAtPoint(soundSettings.audioClip, pos,
                                soundSettings.volume, soundSettings.RandomPitch(), delay, source));
     }
     return(null);
 }
Esempio n. 2
0
    public static AudioSource PlayClipAtPoint(AudioClip clip, Vector3 pos, float volume, float pitch,
                                              float delay            = 0f,
                                              SoundSourceType source = SoundSourceType.Unknown)
    {
        if (!clip)
        {
            return(null);
        }

        if (delay > float.Epsilon)
        {
            _toPlay.Add(new AudioState()
            {
                clip     = clip,
                position = pos,
                pitch    = pitch,
                volume   = volume,
                start    = Time.time,
                delay    = delay
            });
        }

        return(CreateAudioSourceObject(clip, pos, volume, pitch));        // return the AudioSource reference
    }
Esempio n. 3
0
    public static AudioSource PlayClipAtPoint(AudioClip clip, Vector3 pos, float volume, float pitch, SoundSourceType source)
    {
        var tempGO = new GameObject("TempAudio");           // create the temp object

        tempGO.transform.position = pos;                    // set its position
        var aSource = tempGO.AddComponent <AudioSource> (); // add an audio source

        aSource.clip         = clip;                        // define the clip
        aSource.volume       = volume;
        aSource.spatialBlend = 1.0f;
        aSource.minDistance  = 5f;
        aSource.maxDistance  = 100f;
        aSource.pitch        = pitch;
        // set other aSource properties here, if desired
        aSource.Play();               // start the sound
        Destroy(tempGO, clip.length); // destroy object after clip duration
        return(aSource);              // return the AudioSource reference

        if (source == SoundSourceType.Sub)
        {
            aSource.bypassListenerEffects = true;
            aSource.volume = volume + 0.2f;
        }
    }