Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using System;
  6. using System.IO;
  7.  
  8. public class GameManager : MonoBehaviour
  9. {
  10. public GameObject buttonRestart;
  11. public GameObject gameOverImage;
  12. public GameObject grid;
  13. HealthBar h;
  14.  
  15. public enum GameManagerState
  16. {
  17. GamePlay,
  18. GameOver,
  19. }
  20.  
  21. GameManagerState GMState;
  22.  
  23. public GameManagerState getState()
  24. {
  25. return GMState;
  26. }
  27.  
  28. private void Awake()
  29. {
  30. GameObject healthBar = GameObject.Find("HealthBar");
  31. h = healthBar.GetComponent<HealthBar>();
  32. }
  33.  
  34. void Start()
  35. {
  36. GMState = GameManagerState.GamePlay;
  37. UpdateGameManagerState();
  38. }
  39.  
  40. void Update()
  41. {
  42. if (GMState == GameManagerState.GamePlay)
  43. if (HealthBar.gameOver == true)
  44. {
  45. GMState = GameManagerState.GameOver;
  46. UpdateGameManagerState();
  47. }
  48.  
  49. if (GMState == GameManagerState.GameOver)
  50. if (Input.GetKeyDown(KeyCode.R))
  51. {
  52. GMState = GameManagerState.GamePlay;
  53. UpdateGameManagerState();
  54. }
  55. }
  56.  
  57. void UpdateGameManagerState()
  58. {
  59. switch (GMState)
  60. {
  61. case GameManagerState.GamePlay:
  62. if (Time.timeScale == 0.0f)
  63. Time.timeScale = 1.0f;
  64. h.ResetHealth();
  65. GridGenerator gridScript = grid.GetComponent<GridGenerator>();
  66.  
  67. if (gridScript.gridGenerated == true)
  68. {
  69. Destroy(gridScript.player);
  70. for (int i = 0; i < gridScript.roomList.Capacity; i++)
  71. Destroy(gridScript.roomList[i]);
  72. }
  73.  
  74. grid.GetComponent<GridGenerator>().GenerateGrid();
  75. gameOverImage.SetActive(false);
  76. break;
  77.  
  78. case GameManagerState.GameOver:
  79. Time.timeScale = 0.0f;
  80. gameOverImage.SetActive(true);
  81. break;
  82. }
  83. }
  84.  
  85. public void SetGameManagerState(GameManagerState state)
  86. {
  87. GMState = state;
  88. UpdateGameManagerState();
  89. }
  90.  
  91. public void GameOver()
  92. {
  93. GMState = GameManagerState.GamePlay;
  94. UpdateGameManagerState();
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement