using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
    public static GameManager instance{get; private set;}
    public Text distanceTxt;
    public GameObject gameOverPanel;
    public Text thisDistance;
    public Text bestDistance;
    public Text txtEarnings;

    void Awake(){
        instance=this;
    }
    public static void GameOver(){
        instance.gameOverPanel.SetActive(true);
        carController.GameOver();

        instance.thisDistance.text = distanceTravelled + " m";
        instance.bestDistance.text = (PlayerPrefs.HasKey("best")? PlayerPrefs.GetInt("best").ToString() : distanceTravelled.ToString() ) + " m";

        int earnings = (int)(distanceTravelled/10f);
        // DataManager.Money+=earnings;

        instance.txtEarnings.text = "$" +earnings;
    }

    private static int m_distance;
    public static int distanceTravelled {get {
        if(carController.isAlive){
            m_distance = (int)(carController.instance.transform.position.x);
        }

        return m_distance;        
    }} 
    void Update(){
        if(carController.instance.transform.position.x > 0){
            distanceTxt.text = distanceTravelled + " m";
        }
    }

    public void Reload(){
        SceneManager.LoadScene("LevelGen");
    }

    public void LoadMenu(){
        SceneManager.LoadScene("Menu");

    }
}
