using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Score : MonoBehaviour {

	public Text scoreText, highScoreText, gameOverText;
	int score;
	public static int highScore;
	public bool gameOver;
	public GameObject menuButton;
	void Start () 
	{
		highScore=PlayerPrefs.GetInt("HighScore", 0);
		scoreText.text = "Score: 0";
		highScoreText.text = "High Score: " + highScore.ToString();
		score = 0;
	}
	
	// Update is called once per frame
	void Update () 
	{
		if (gameOver && Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)
		{
			float position = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position).y;
			if(position<13)
				SceneManager.LoadScene(SceneManager.GetActiveScene().name);
		}
	}

	public void enemyKilled(int bonus)
	{
		score += bonus;
		scoreText.text = "Score: " + score.ToString ();
		if (score > highScore)
		{
			highScoreText.text = "High Score: " + score.ToString();
		}
	}
	public void saveScore()
	{
		menuButton.SetActive(true);
		gameOverText.gameObject.SetActive(true);
		if (highScore < score)
			PlayerPrefs.SetInt("HighScore", score);
		gameOver = true;
	}

	public void mainMenu()
	{
		SceneManager.LoadScene("mainmenu");
	}
}
