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

public class GameController : MonoBehaviour
{
    public static int InitialTime = 300; // Time until win, listed in seconds (for use with deltaTime)
    public static float TimeToFinish = InitialTime;
    public static float NormalisedTime = TimeToFinish / InitialTime;
    public GameObject GameText;
    public GameObject SplashText;

    //publict scriptVariable variableName
    public TimerBar timebar;

    void Start()
    {
        GameText.GetComponent<TextMesh>().text = "";
        SplashText.GetComponent<TextMesh>().text = "";
    }

    // Update is called once per frame
    void Update()
    {

        if (TimeToFinish > 0)
        {
            TimeToFinish -= Time.deltaTime; // decrement time value (compensates for frame time)
        }
        else
        {
            TimeToFinish = 0;
        }
        NormalisedTime = TimeToFinish / InitialTime;
        timebar.SetSize(NormalisedTime);

        if (TimeToFinish == 0) 
        {
            GameText.GetComponent<TextMesh>().text = "You Win!";
            SplashText.GetComponent<TextMesh>().text = "You Have escaped the Asteroid belt for now.";
        }
    }
}
