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

public class GameManager : MonoBehaviour
{
    public static GameManager instance;
    public float worldScrollingSpeed = 0.2f;
    public Text scoreText;
    private float score;

    public bool inGame;
    public GameObject resetButton;

    void Start()
    {
        if( instance == null){
            instance = this;
        }
        InitializeGame();
    }

    void Update()
    {
        
    }

    void InitializeGame(){
        inGame = true;
    }

    public void GameOver(){
        inGame = false;
        resetButton.SetActive(true);
    }

    public void RestartGame(){
        SceneManager.LoadScene(0);
    }

    void FixedUpdate(){
        if (!GameManager.instance.inGame) return;
        score += worldScrollingSpeed;
        UpdateOnScreenScore();
    }

    void UpdateOnScreenScore(){
        scoreText.text = score.ToString("0");
    }
}
