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

using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class LoadLevel : MonoBehaviour {

	public GameObject loadingScreenObj;
	public Slider slider;
	public int levelToLoad;

	AsyncOperation async;

	public void LoadingSceneExample(int level2){
		levelToLoad = level2;
		StartCoroutine (LoadingScreen(levelToLoad));
	}

	IEnumerator LoadingScreen(int level){
		loadingScreenObj.SetActive (true);
		async = SceneManager.LoadSceneAsync (level);
		async.allowSceneActivation = false;

		while (async.isDone == false) {
			slider.value = async.progress;
			if(async.progress == 0.9f){
				slider.value = 1f;
				async.allowSceneActivation = true;
			}

			yield return null;
		}
	}
}
