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

public class ShieldCodeGenerator : MonoBehaviour {

	public float codeRefreshTime = 30.0f;

	private float startRefresh;

	// Use this for initialization
	void Start () {

		Dictionaries.dictionaries.shieldCode = Dictionaries.dictionaries.shieldcodes.masterCodes[Random.Range(0, Dictionaries.dictionaries.shieldcodes.masterCodes.Length)];
		gameObject.GetComponent<Text>().text = Dictionaries.dictionaries.shieldCode;
		gameObject.GetComponent<Text>().enabled = false;
		startRefresh = Time.time;
	
	}
	
	// Update is called once per frame
	void Update () {

		if (Dictionaries.dictionaries.startGame)
		{
			gameObject.GetComponent<Text>().enabled = true;


			if (Time.time - startRefresh > codeRefreshTime)
			{
	            refreshShieldCode();
				startRefresh = Time.time;
			}	
		}
	}

    public void refreshShieldCode()
    {
        Dictionaries.dictionaries.shieldCode = Dictionaries.dictionaries.shieldcodes.masterCodes[Random.Range(0, Dictionaries.dictionaries.shieldcodes.masterCodes.Length)];
        gameObject.GetComponent<Text>().text = Dictionaries.dictionaries.shieldCode;
    }
}
