using UnityEngine;
using System.Collections;

public class NavigationPrompt : MonoBehaviour {
    bool showDialog;
    // Use this for initialization
    private string level;
    void OnCollisionEnter2D(Collision2D col)
    {
        if(NavigationMenager.CanNavigate(this.tag))
        {
            showDialog = true;
        }
        
    }
    void OnTriggerEnter2D(Collider2D col)
    {
        Debug.Log(this.tag);
        Debug.Log(NavigationMenager.CanNavigate(this.tag));
        if (NavigationMenager.CanNavigate(this.tag))
        {
            showDialog = true;
        }

    }

    void OnGUI()
    {
        if (showDialog)
        {
            GUI.BeginGroup(new Rect(Screen.width / 2 - 150, 50, 300, 250));

            GUI.Box(new Rect(0,0,300,250) , "");
            GUI.Label(new Rect(15,10,300,68),"Do you want to travel to " + NavigationMenager.GetRouteInfo(this.tag) + "?");
            if (GUI.Button(new Rect(55, 100, 180, 40), "Travel"))
            {
                showDialog = false;
                level = this.tag;
                StartCoroutine(ChangeLevel());

            }
            if (GUI.Button(new Rect(55, 150, 180, 40), "Stay"))
            {
                showDialog = false;
                //Application.LoadLevel(1);
            }
            GUI.EndGroup();
        }
     
   

        

   
}
    IEnumerator ChangeLevel()
    {
        // pronalzi objekat za koji je zakacena tekstura i skripta za tranziciju izmedju scena
        float fadeTime = GameObject.Find("GM").GetComponent<FadeInOutManager>().BeginFade(1);
        yield return new WaitForSeconds(fadeTime);
        // promena scene
        UnityEngine.SceneManagement.SceneManager.LoadScene(level);
    }
}
