using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioController : MonoBehaviour
{
    bool fadeout;
    bool refadeit;
    bool fadein;
    public void FadeOut(bool refade)
    {
        print("fade");
        fadeout = true;
        refadeit = refade;
    }

    public void FixedUpdate()
    {
        if (fadeout && GetComponent<AudioSource>().volume > 0)
        {
            GetComponent<AudioSource>().volume = Mathf.MoveTowards(GetComponent<AudioSource>().volume, 0, 0.01f);
        }
        else if (fadeout)
        {
            fadeout = false;
            if (refadeit) fadein = true;
        }

        if (fadein && GetComponent<AudioSource>().volume < 1)
        {
            GetComponent<AudioSource>().volume = Mathf.MoveTowards(GetComponent<AudioSource>().volume, 1, 0.0005f);
        }
        else if (fadein)
        {
            fadein = false;
        }
    }
}
