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

public class nextLevel : MonoBehaviour {

    AudioSource doorSound;

    public string nextScene;

	// Use this for initialization
	void Start () {
        doorSound = GetComponent<AudioSource>();
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    private void OnTriggerEnter(Collider other)
    {
        if(other.tag=="Player")
        {
            /*int nextSceneIndex = SceneManager.GetActiveScene().buildIndex + 1;
            if (SceneManager.sceneCount > nextSceneIndex)
            {
                SceneManager.LoadScene(nextSceneIndex);
            }*/
            //Debug.Log("LOAD NEXT");
            StartCoroutine(playSoundThenLoad());
        }
    }

    IEnumerator playSoundThenLoad()
    {
        doorSound.Play();
        yield return new WaitForSeconds(doorSound.clip.length);

        SceneManager.LoadScene(nextScene);
    }
}
