Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using TMPro;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class GameManager : MonoBehaviour
- {
- public static GameManager Instance;
- [SerializeField] private bool gameStarted = false;
- public bool GameStarted() => gameStarted;
- [SerializeField] private Snake[] snakes;
- [SerializeField] private Food food;
- private void Awake()
- {
- if (Instance == null)
- Instance = this;
- else
- DestroyImmediate(this);
- }
- private void Start()
- {
- ResetGame();
- }
- private void StartGame()
- {
- gameStarted = true;
- }
- private void LateUpdate()
- {
- CheckForWin();
- }
- private void CheckForWin()
- {
- bool gameEnded = false;
- foreach (Snake snake in snakes)
- {
- if (!snake.isAlive())
- {
- gameEnded = true;
- Debug.Log($"{snake.name} died.");
- }
- }
- if (gameEnded)
- ResetGame();
- }
- private void ResetGame()
- {
- gameStarted = false;
- foreach (Snake snake in snakes)
- {
- snake.ResetState();
- }
- food.ResetState();
- Invoke(nameof(StartGame), 3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement