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

public class GameManager : MonoBehaviour {
    public GameObject gameOverPanel;	// The panel for the game over object
    public GameObject winPanel;
    public int nextSceneIndex;
    public AudioSource audio;

	// Use this for initialization
	void Start () {
        gameOverPanel.SetActive(false);	// The game over panel is only diplayed on game over
        winPanel.SetActive(false);
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    void PlayerSeenByCamera()
    {
        gameObject.BroadcastMessage("GoToPlayer");
    }

    void GameOver(float delay)
    {
        // Trigger the game over message
        audio.Play();
        gameOverPanel.SetActive(true);
        // Restart the game after a delay
        Invoke("Restart", delay);
    }

    void Restart()
    {
        // Reload the scene
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }

    void Win(float delay)
    {
        winPanel.SetActive(true);
        //Invoke("Restart", delay);
        Invoke("NextScene", delay);
    }

    void NextScene(){
        SceneManager.LoadScene(nextSceneIndex);
    }
}
