Advertisement
gandalfbialy

Untitled

May 17th, 2025
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. using System.Collections.Generic;
  4.  
  5. public class GameManager : MonoBehaviour
  6. {
  7. public static GameManager instance;
  8. public List<GameObject> bricks = new List<GameObject>();
  9. public ArcanoidBall ball;
  10. public bool isGameRunning = false;
  11. public int lives;
  12.  
  13. void Awake()
  14. {
  15. if (instance == null)
  16. {
  17. instance = this.gameObject.GetComponent<GameManager>();
  18. }
  19.  
  20. bricks.AddRange(GameObject.FindGameObjectsWithTag("Brick"));
  21. lives = 3;
  22. }
  23.  
  24. void Update()
  25. {
  26. if (Input.GetKey(KeyCode.Space) && !isGameRunning)
  27. {
  28. ball.RunBall();
  29. isGameRunning = true;
  30. }
  31.  
  32. if (isGameRunning && bricks.Count <= 0)
  33. {
  34. EndGame(true);
  35. }
  36.  
  37. if (!isGameRunning && Input.GetKey(KeyCode.R))
  38. {
  39. SceneManager.LoadScene(0);
  40. }
  41.  
  42. if (isGameRunning && lives <= 0)
  43. {
  44. EndGame(false);
  45. }
  46. }
  47.  
  48. public void EndGame(bool isWin)
  49. {
  50. isGameRunning = false;
  51. string endGameText = isWin ? "Wygrana!" : "Przegrana!";
  52. Debug.Log(endGameText);
  53. ball.StopBall();
  54. }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement