using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour {

	public static GameManager instance;

	public AudioSource bonusAudio;
	public AudioSource nextLevelAudio;
	public AudioSource loseAudio;



	public  GameObject b;

	public GameObject loseScreen;
	public Restart restartButton;
	public GameObject plataforma;
	public GameObject star;
	public int onBonus=1;

	private Rigidbody2D rb;

	private bool plataformaDown=false;

	void Start(){
		if(instance==null){
			instance = this;
		}
		rb = plataforma.GetComponent<Rigidbody2D> ();
	}
	public void OnBonus(){

		bonusAudio.Play ();
		onBonus = 3;
		b.SetActive (true);
		StartCoroutine (BonusTime());
	}

	public void OnDead(){
		if (!loseScreen.activeSelf) {
			loseAudio.Play ();
			loseScreen.SetActive (true);
		}
	}
	public void LevelUp(){
		nextLevelAudio.Play ();
		//bonus
		if((Random.Range(0,100)>80)&& star.activeSelf==false){
			star.SetActive (true);
		}
		//
		PlayerStat.instance.playerTime += 0.25f;
		PlayerStat.instance.score += 1*onBonus;
		Spawner.instance.PushPattern ();
	}
	IEnumerator BonusTime(){
		yield return new WaitForSeconds (10);
		b.SetActive (false);
		onBonus = 1;
	}
}
