Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class GameManager : MonoBehaviour
- {
- //Game Manager Instance
- public static GameManager instance;
- //List of bricks
- public List<GameObject> bricks = new List<GameObject>();
- //Our ball script
- public ArcanoidBall ball;
- //is the game in progress?
- bool gameRun = false;
- void Awake()
- {
- //Assigning an object to instance. Creating Singleton
- if(instance == null)
- {
- instance = this;
- }
- //Getting all Bricks and (by Brick tag) and adding them to the list
- bricks.AddRange(GameObject.FindGameObjectsWithTag("Brick"));
- }
- void Update()
- {
- //Starting the game when clicking space (if it's not on yet)
- if (Input.GetKeyDown(KeyCode.Space) && !gameRun)
- {
- ball.RunBall();
- gameRun = true;
- }
- //Ending the game when all bricks are gone
- if(gameRun && bricks.Count == 0)
- {
- EndGame(true);
- }
- //If the game is over, reset the scene with R key
- if(!gameRun)
- {
- if(Input.GetKeyDown(KeyCode.R))
- {
- SceneManager.LoadScene(0);
- }
- }
- }
- //Ending game function
- public void EndGame(bool win)
- {
- gameRun = false;
- string txt = win ? "Wygrana!" : "Przegrana!";
- Debug.Log(txt);
- ball.StopBall();
- }
- }
Add Comment
Please, Sign In to add comment