Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class GM : MonoBehaviour {
  6.  
  7. public int lives = 3;
  8. public int bricks = 36;
  9. public float resetDelay = 1f;
  10. public Text livesText;
  11. public GameObject gameOver;
  12. public GameObject youWon;
  13. public GameObject bricksPrefab;
  14. public GameObject paddle;
  15. public GameObject deathParticles;
  16. public static GM instance = null;
  17.  
  18. private GameObject clonePaddle;
  19.  
  20. // Use this for initialization
  21. void Awake ()
  22. {
  23. if (instance == null)
  24. instance = this;
  25. else if (instance != this)
  26. Destroy (gameObject);
  27.  
  28. Setup();
  29.  
  30. }
  31.  
  32. public void Setup()
  33. {
  34. clonePaddle = Instantiate(paddle, transform.position, Quaternion.identity) as GameObject;
  35. Instantiate(bricksPrefab, transform.position, Quaternion.identity);
  36. }
  37.  
  38. void CheckGameOver()
  39. {
  40. if (bricks < 1)
  41. {
  42. youWon.SetActive(true);
  43. Time.timeScale = .25f;
  44. Invoke ("Reset", resetDelay);
  45. }
  46.  
  47. if (lives < 1)
  48. {
  49. gameOver.SetActive(true);
  50. Time.timeScale = .25f;
  51. Invoke ("Reset", resetDelay);
  52. }
  53.  
  54. }
  55.  
  56. void Reset()
  57. {
  58. Time.timeScale = 1f;
  59. Application.LoadLevel(Application.loadedLevel);
  60. }
  61.  
  62. public void LoseLife()
  63. {
  64. lives--;
  65. livesText.text = "Lives: " + lives;
  66. Instantiate(deathParticles, clonePaddle.transform.position, Quaternion.identity);
  67. Destroy(clonePaddle);
  68. Invoke ("SetupPaddle", resetDelay);
  69. CheckGameOver();
  70. }
  71.  
  72. void SetupPaddle()
  73. {
  74. clonePaddle = Instantiate(paddle, transform.position, Quaternion.identity) as GameObject;
  75. }
  76.  
  77. public void DestroyBrick()
  78. {
  79. bricks--;
  80. CheckGameOver();
  81. }
  82. }
  83.  
  84.  
  85. public class GameManager : MonoBehaviour {
  86. public Text timeCounter;
  87. private float levelStartTime;
  88. // Use this for initialization
  89. void Start () {
  90. this.levelStartTime = Time.fixedTime;
  91. }
  92.  
  93.  
  94. // Update is called once per frame
  95. void Update () {
  96. this.timeCounter.text = (Time.fixedTime - this.levelStartTime) + " seconds";
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement