using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class GameController : MonoBehaviour {
	
	public bool playerCaught = false;
	public Text panicLevel;
	public GameObject player;
	private PlayerController pc;
	public GameObject retryButton;
	public AudioClip alarmSound;
	private AudioSource audio1;
	public GameObject PauseText;

	public float panicValue;
	private bool pauseTog = false;

	// Use this for initialization
	void Start () {

		pc = player.GetComponent<PlayerController>();
		audio1 = gameObject.GetComponent<AudioSource>();
	}
	
	// Update is called once per frame
	void Update () {

		panicValue = pc.panicTotal;

	}
	
	void OnGUI()
	{
		panicLevel.text = "Panic Level: " + (pc.panicTotal * 100.0f).ToString("0") + "%";
	}
	
	public void PauseGame()
	{
		Time.timeScale = 1 - Time.timeScale;


	//	if (Time.timeScale > 0.5f)
			pauseTog = !pauseTog;
		PauseText.SetActive (pauseTog);

	}
	
	public void PlayerCaught()
	{
		GameObject[] players = GameObject.FindGameObjectsWithTag ("Player");
		for (int i = 0; i < players.Length; i++) {
			PlayerController pc = players[i].GetComponent<PlayerController>();
			pc.Surrender();
		}
		playerCaught = true;
		retryButton.SetActive(true);
		audio1.clip = alarmSound;
		audio1.Play();
		
	}
	
	public void ResetLevel()
	{
		Application.LoadLevel (Application.loadedLevelName);
	}
	
	
}
