<commit_before>﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public enum GameStates{
	PREGAME, 	//State before play
	INGAME, 	//State when play and player alive
	GAMEOVER ,	//State when player dead
}
	
public class GameManager : MonoBehaviour {
	[Header("Text")]
	public Text scoreText;
	public Text newBestScoreText; 
	public Text gameoverScoreText; 
	public Text gameoverBestScoreText; 
	public Text gamesPlayedText; 

	[Header("Canvas UI")]
	public Canvas pregameCanvas; 
	public Canvas gameoverCanvas; 
	public Canvas ingameCanvas;
	public Canvas pauseCanvas; 

	[HideInInspector]
	public static GameManager instance;
	public GameStates currentState;
	private int score;

	void Awake () {
		instance = this;
		currentState = GameStates.PREGAME; //Begin with PREGAME state
	}

	public void addScore(){
		score++;
		scoreText.text = score.ToString();
	}

	public void startGame(){
		currentState = GameStates.INGAME; //Change state to INGAME
		pregameCanvas.gameObject.SetActive (false); //Hide pregameCanvas
		ingameCanvas.gameObject.SetActive (true); //Show ingameCanvas
		PlayerPrefs.SetInt("gamesPlayed", PlayerPrefs.GetInt ("gamesPlayed", 0) + 1 );
	}
	
	public void gameOver(){
		currentState = GameStates.GAMEOVER;

		checkHighScore ();
		gamesPlayedText.text += PlayerPrefs.GetInt ("gamesPlayed", 0);
		gameoverScoreText.text = score.ToString();
		gameoverBestScoreText.text += PlayerPrefs.GetInt ("bestscore", 0);

		StartCoroutine (ShowGameoverCanvas ());
	}

	public void restartGame(){
		Application.LoadLevel(Application.loadedLevel);
	}
	
	IEnumerator ShowGameoverCanvas(){
		yield return new WaitForSeconds (1.5f);

		gameoverCanvas.gameObject.SetActive (true);
		ingameCanvas.gameObject.SetActive (false);
	}
	
	private void checkHighScore(){
		if( score > PlayerPrefs.GetInt("bestscore", 0) ) {
			PlayerPrefs.SetInt("bestscore", score);
			newBestScoreText.gameObject.SetActive(true);
		}
	}
}<commit_msg>add Pause and Resume method<commit_after>﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public enum GameStates{
	PREGAME, 	//State before play
	INGAME, 	//State when play and player alive
	GAMEOVER ,	//State when player dead
}
	
public class GameManager : MonoBehaviour {
	[Header("Text")]
	public Text scoreText;
	public Text newBestScoreText; 
	public Text gameoverScoreText; 
	public Text gameoverBestScoreText; 
	public Text gamesPlayedText; 

	[Header("Canvas UI")]
	public Canvas pregameCanvas; 
	public Canvas gameoverCanvas; 
	public Canvas ingameCanvas;
	public Canvas pauseCanvas; 

	[HideInInspector]
	public static GameManager instance;
	public GameStates currentState;
	private int score;

	void Awake () {
		instance = this;
		currentState = GameStates.PREGAME; //Begin with PREGAME state
	}

	public void addScore(){
		score++;
		scoreText.text = score.ToString();
	}

	public void startGame(){
		currentState = GameStates.INGAME; //Change state to INGAME
		pregameCanvas.gameObject.SetActive (false); //Hide pregameCanvas
		ingameCanvas.gameObject.SetActive (true); //Show ingameCanvas
		PlayerPrefs.SetInt("gamesPlayed", PlayerPrefs.GetInt ("gamesPlayed", 0) + 1 );
	}
	
	public void gameOver(){
		currentState = GameStates.GAMEOVER;

		checkHighScore ();
		gamesPlayedText.text += PlayerPrefs.GetInt ("gamesPlayed", 0);
		gameoverScoreText.text = score.ToString();
		gameoverBestScoreText.text += PlayerPrefs.GetInt ("bestscore", 0);

		StartCoroutine (ShowGameoverCanvas ());
	}

	public void restartGame(){
		Application.LoadLevel(Application.loadedLevel);
	}
	
	IEnumerator ShowGameoverCanvas(){
		yield return new WaitForSeconds (1.5f);

		gameoverCanvas.gameObject.SetActive (true);
		ingameCanvas.gameObject.SetActive (false);
	}
	
	private void checkHighScore(){
		if( score > PlayerPrefs.GetInt("bestscore", 0) ) {
			PlayerPrefs.SetInt("bestscore", score);
			newBestScoreText.gameObject.SetActive(true);
		}
	}

	public void Pause(){
		Time.timeScale = 0; //Change timeScale to 0
		pauseCanvas.gameObject.SetActive (true); //Show pauseCanvas
	}

	public void Resume(){
		Time.timeScale = 1; //Change timeScale to 1
		pauseCanvas.gameObject.SetActive (false); //Hide pauseCanvas
	}
}
{'fraction_non_alphanumeric': 0.10574162679425837, 'fraction_numerical': 0.00430622009569378, 'mean_word_length': 4.798890429958391, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2825529', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1299, 'n_words': 332}