Newer
Older
app-47-android / Assets / Scripts / GameManager.cs
@a_kuznecov a_kuznecov on 22 Jun 2023 1 KB First Commit
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public int score;
    [SerializeField] private TextMeshProUGUI scoreText;
    [SerializeField] private Cell[] cells;
    [SerializeField] private Cell2[] cells2;
    public TextMeshPro timeText;

    [SerializeField] private Cell2[] cellsForGameOverCheck;
    public float time;
    public bool gameOver;
    [SerializeField] private GameObject handTutor;

    public static GameManager Instance;
    public int cellsFullCount;
    [SerializeField] private GameObject gameOverPanel;

    private void Awake()
    {
        if (Instance == null)
            Instance = this;

        if (!PlayerPrefs.HasKey("TutorFinger"))
        {
            handTutor.SetActive(true);
            PlayerPrefs.SetInt("TutorFinger", 0);


        }

    }
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.Space))
        {
            GameOverCheck();
        }
        if (!gameOver)
        {
            time += Time.deltaTime;
            float minutes = Mathf.FloorToInt(time / 60);
            float seconds = Mathf.FloorToInt(time % 60);
            timeText.text = string.Format("{0}:{1:00}", minutes, seconds);
        }
    }

    public void GameOverCheck()
    {
        cellsFullCount = 0;
        for (int i = 0; i < cellsForGameOverCheck.Length; i++)
        {
            if (cellsForGameOverCheck[i].ItemInCell != null)
            {
                cellsFullCount++;
            }
            else
            {
                cellsFullCount--;
            }
        }
        if (cellsFullCount == 4)
        {
            gameOver = true;
            gameOverPanel.SetActive(true);
        }
    }
    public void SetScore(int scoreCount)
    {
        score += scoreCount;
        scoreText.text = "score " + score.ToString();
    }
}