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

public class MusicController : MonoBehaviour
{
    AudioSource music = null;


    private float startTime = 0.0f;
    private float halfTime = 1.0f;

    // Start is called before the first frame update
    void Start()
    {
        music = GetComponent<AudioSource>();
        startTime = Time.time;
        halfTime = FindObjectOfType<CustomerManager>().CurrentLevel.ExpectedLevelLength / 2.0f;

    }

    // Update is called once per frame
    void Update()
    {
        float elapsedTime = Time.time - startTime;

        if (elapsedTime < halfTime)
        {
            music.volume = 0.25f;
        }
        else if (elapsedTime > halfTime)
        {
            music.volume = 0.25f + 0.7f * (elapsedTime - halfTime) / halfTime;
        }
    }
}
