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

public class Scenes : MonoBehaviour 
{

	// VARIABLES DE LOADING
	public GameObject loadingScreen;

	void Start()
	{
		//PlayerPrefs.DeleteAll ();
	}


	// TITLE
	public void Title()
	{	
		StartCoroutine (DisplayLoadingScreenTitle ("Title"));				
		Time.timeScale = 1;													
	}

	IEnumerator DisplayLoadingScreenTitle(string loadScene)
	{
		loadingScreen.SetActive (true);
		yield return new WaitForSeconds (0.3f);														
		AsyncOperation async = SceneManager.LoadSceneAsync ("Title", LoadSceneMode.Single); 	


		while (!async.isDone) 												
		{
			yield return null;
		}
	}


	// MAIN MAP
	public void Map()
	{	
		StartCoroutine (DisplayLoadingScreenMap ("Map"));				
		Time.timeScale = 1;													
	}

	IEnumerator DisplayLoadingScreenMap(string loadScene)
	{
		loadingScreen.SetActive (true);
		yield return new WaitForSeconds (0.3f);														
		AsyncOperation async = SceneManager.LoadSceneAsync ("Map", LoadSceneMode.Single); 	


		while (!async.isDone) 												
		{
			yield return null;
		}
	}


	// CREDITS
	public void Credits()
	{	
		StartCoroutine (DisplayLoadingScreenCredits ("Credits"));				
		Time.timeScale = 1;													
	}

	IEnumerator DisplayLoadingScreenCredits(string loadScene)
	{
		loadingScreen.SetActive (true);
		yield return new WaitForSeconds (0.3f);														
		AsyncOperation async = SceneManager.LoadSceneAsync ("Credits", LoadSceneMode.Single); 	


		while (!async.isDone) 												
		{
			yield return null;
		}
	}


	// ISLAND 1
	public void Island1()
	{	
		StartCoroutine (DisplayLoadingScreenIsland1 ("Island1"));				
		Time.timeScale = 1;													
	}

	IEnumerator DisplayLoadingScreenIsland1(string loadScene)
	{
		loadingScreen.SetActive (true);
		yield return new WaitForSeconds (0.3f);														
		AsyncOperation async = SceneManager.LoadSceneAsync ("Island1", LoadSceneMode.Single); 	


		while (!async.isDone) 												
		{
			yield return null;
		}
	}


	// ISLAND 2
	public void Island2()
	{	
		StartCoroutine (DisplayLoadingScreenIsland2 ("Island2"));				
		Time.timeScale = 1;													
	}

	IEnumerator DisplayLoadingScreenIsland2(string loadScene)
	{
		loadingScreen.SetActive (true);
		yield return new WaitForSeconds (0.3f);														
		AsyncOperation async = SceneManager.LoadSceneAsync ("Island2", LoadSceneMode.Single); 	


		while (!async.isDone) 												
		{
			yield return null;
		}
	}


	// ISLAND 3
	public void Island3()
	{	
		StartCoroutine (DisplayLoadingScreenIsland3 ("Island3"));				
		Time.timeScale = 1;													
	}

	IEnumerator DisplayLoadingScreenIsland3(string loadScene)
	{
		loadingScreen.SetActive (true);
		yield return new WaitForSeconds (0.3f);														
		AsyncOperation async = SceneManager.LoadSceneAsync ("Island3", LoadSceneMode.Single); 	


		while (!async.isDone) 												
		{
			yield return null;
		}
	}

}







