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

public class ResultController : MonoBehaviour {

	public GameObject lastScoreText, highScoreText, newRecordText;
	public float maxGlow;

	private bool isLighting = true;
	private float currentGlow;
	private Color initColor;

	// Use this for initialization
	void Start () {
		initColor = newRecordText.GetComponent<Text>().color;

		int lastScore = PlayerPrefs.GetInt ("lastScore");
		int highScore = PlayerPrefs.GetInt ("highScore");
		if (lastScore > highScore) {
			highScore = lastScore;
			PlayerPrefs.SetInt ("highScore", lastScore);
		} else {
			newRecordText.SetActive (false);
		}
		lastScoreText.GetComponent<Text>().text = PlayerPrefs.GetInt("lastScore").ToString();
		highScoreText.GetComponent<Text>().text = PlayerPrefs.GetInt("highScore").ToString();

		if (PlayerPrefs.GetInt ("enableAudio") == 0) {
			AudioListener.volume = 0.0f;
		} 
		else {
			AudioListener.volume = 1.0f;
		}
	}

	void Update () {
		if(isLighting) {
			if( currentGlow < maxGlow ) {
				currentGlow += 0.02f;
				newRecordText.GetComponent<Text>().color = new Color (initColor.r + currentGlow, initColor.g, initColor.b);
			}
			else {
				isLighting = false;
			}
		}
		else {
			if( currentGlow > 0 ) {
				currentGlow -= 0.02f;
				newRecordText.GetComponent<Text>().color = new Color (initColor.r + currentGlow, initColor.g, initColor.b );
			}
			else {
				isLighting = true;
			}
		}
	}
}
