Advertisement
drakon-firestone

Untitled

Dec 27th, 2023 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class GameManager : MonoBehaviour
  8. {
  9. public static GameManager Instance;
  10.  
  11. public Transform bricks;
  12.  
  13. public ArkanoidBall ball;
  14.  
  15. bool gameRun = false;
  16.  
  17. private void Awake()
  18. {
  19. if (Instance == null) Instance = this;
  20. }
  21.  
  22. // Update is called once per frame
  23. void Update()
  24. {
  25. if (Input.GetKey(KeyCode.Space) && !gameRun)
  26. {
  27. ball.RunBall();
  28. gameRun = true;
  29. }
  30.  
  31. Debug.Log(bricks.childCount);
  32. if(gameRun && bricks.childCount == 0)
  33. {
  34. EndGame(true);
  35. }
  36.  
  37. if (!gameRun && Input.GetKeyDown(KeyCode.R))
  38. {
  39. SceneManager.LoadScene(0);
  40. }
  41. }
  42.  
  43. public void EndGame(bool win)
  44. {
  45. gameRun = false;
  46. string text = win ? "Wygrana!" : "Przegrana!";
  47. Debug.Log(text);
  48. ball.StopBall();
  49. }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement