Beispiel #1
0
    public IEnumerator MusicCrossFade(AudioMixer audioMixer, string fadeOutParamName, string fadeInParamName, float crossFadeDuration, string fadedOutMusicName, string fadeInMusicName)
    {
        float currentTime = 0f;
        float normalizedValue;

        Play(fadeInMusicName);
        while (currentTime <= crossFadeDuration)
        {
            currentTime    += Time.unscaledDeltaTime;
            normalizedValue = currentTime / crossFadeDuration;
            audioMixer.SetFloat(fadeOutParamName, EasingFunction.EaseInCirc(0f, -80f, normalizedValue));
            audioMixer.SetFloat(fadeInParamName, EasingFunction.EaseOutCirc(-80f, 0f, normalizedValue));
            yield return(null);
        }
        audioMixer.SetFloat(fadeOutParamName, -80f);
        audioMixer.SetFloat(fadeInParamName, 0f);
        Stop(fadedOutMusicName);
        yield return(null);
    }
Beispiel #2
0
    IEnumerator DisappearingAnimation(float endingOffset, float duration, float minDelay, float maxDelay)
    {
        float elapsedTime = 0;

        Vector3 startingPos = transform.position;
        Vector3 endPos      = new Vector3(transform.position.x, transform.position.y + endingOffset, transform.position.z);

        _renderer.material.color = opaqueColor;

        yield return(new WaitForSecondsRealtime(Random.Range(minDelay, maxDelay)));

        while (elapsedTime < duration)
        {
            _renderer.material.color = Color.Lerp(opaqueColor, transparantColor, (elapsedTime / duration));
            float newYPos = EasingFunction.EaseInCirc(startingPos.y, endPos.y, (elapsedTime / duration));
            transform.position = new Vector3(transform.position.x, newYPos, transform.position.z);
            elapsedTime       += Time.unscaledDeltaTime;
            yield return(null);
        }
        _renderer.material.color = transparantColor;
        transform.position       = endPos;
    }