Esempio n. 1
0
    public void PlayAtPosition(SoundId id, Vector2 pos)
    {
        float dist = Vector2.Distance(this.player.transform.position, pos);

        if (dist > this.spatialSoundsMaxDistance)
        {
            return;
        }

        Sound sound = this.sounds.Find(o => o.id == id);

        if (sound == null)
        {
            Debug.LogWarning("Couldn't find sound with id " + id.ToString());
            return;
        }

        sound.ApplyPitch(this.sfxSource);

        float t = (dist - this.spatialSoundsMinDistance) / (this.spatialSoundsMaxDistance - this.spatialSoundsMinDistance);

        t = Mathf.Clamp01(t);

        this.sfxSource.PlayOneShot(sound.clip, sound.volume * this.spatialSoundFalloffCurve.Evaluate(t));
    }
Esempio n. 2
0
    public void PlaySfx(SoundId id)
    {
        Sound sound = this.sounds.Find(o => o.id == id);

        if (sound == null)
        {
            Debug.LogWarning("Couldn't find sound with id " + id.ToString());
            return;
        }

        sound.ApplyPitch(this.sfxSource);

        this.sfxSource.PlayOneShot(sound.clip, sound.volume);
    }