Exemplo n.º 1
0
    public IEnumerator CO_FadeOut(AudioSource source, float duration, float volume)
    {
        float eleapsedTime = 0f;
        float beginVolume  = 1;

        while (eleapsedTime < duration)
        {
            eleapsedTime += Time.deltaTime;
            source.volume = beginVolume - SDMath.Map(eleapsedTime, 0, duration, 0, 1 - volume);
            yield return(null);
        }
        source.volume = volume;
        source.Stop();
    }
Exemplo n.º 2
0
    public IEnumerator CO_FadeIn(AudioSource source, float duration, float volume)
    {
        float eleapsedTime = 0f;
        float beginVolume  = 0;

        source.Play();
        while (eleapsedTime < duration)
        {
            eleapsedTime += Time.deltaTime;
            source.volume = SDMath.Map(eleapsedTime, 0, duration, beginVolume, volume);
            yield return(null);
        }
        source.volume = volume;
    }