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

public class GameStart : MonoBehaviour {
    
    public float timeBeforeFadeIn;

    IEnumerator Start ()
    {

        AsyncOperation propsLoader = SceneManager.LoadSceneAsync("RoomProps", LoadSceneMode.Additive);
        while (!propsLoader.isDone)
        {
            yield return 0;
        }

        //StartCoroutine(waitUntilMusicFinishedBeforePlayingAmbience());
        StartCoroutine(waitABitBeforeFadingIn());
    }
    
    /*IEnumerator waitUntilMusicFinishedBeforePlayingAmbience ()
    {
        float timeAtStart = Time.unscaledTime;
        while (Time.unscaledTime - timeAtStart < estimatedIntroMusicLength)
        {
            yield return null;
        }
    }*/

    IEnumerator waitABitBeforeFadingIn ()
    {
        float timeAtStart = Time.unscaledTime;
        while (Time.unscaledTime - timeAtStart < timeBeforeFadeIn)
        {
            yield return null;
        }
        FadeCanvas.instance.setFade(false);
        AudioManager.instance.Play("music_opening");
        AudioManager.instance.Play("ambience");
    }
}
