Advertisement
gOzaru

GameControl

Jun 25th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6.  
  7. public class GameControl : MonoBehaviour
  8. {
  9. public static GameControl instance; //to make function be accessible from other class.
  10. public GameObject gameOverMenu, playBtn, pauseBtn;
  11. public Text scoreText, bestScore, gameOverText, scoreTextB;
  12. public bool gameOver = false;
  13. public float scrollSpeedLand = -1.25f;
  14. public float scrollSpeedBg = -0.0625f;
  15. public float scrollSpeedCloud = -0.0125f;
  16. private int score = 0;
  17.  
  18. private bool paused = false;
  19. private bool mainMenu, restart = false;
  20.  
  21. void Start()
  22. {
  23. playBtn.gameObject.SetActive(false);
  24. pauseBtn.gameObject.SetActive(true);
  25. }
  26.  
  27. void Awake()
  28. {
  29. //if start game and find no instance of gameControl, then this is the instance
  30. if (instance == null)
  31. instance = this;
  32. else if (instance != this)
  33. Destroy(gameObject);
  34. }
  35.  
  36. public void BirdDied()
  37. {
  38. gameOverMenu.gameObject.SetActive(true);
  39. pauseBtn.gameObject.SetActive(false);
  40. gameOverText.text = "Game Over";
  41. gameOver = true;
  42.  
  43. if (score > Main.instance.GetHighScore())
  44. {
  45. Main.instance.SetHighScore(score);
  46. }
  47. scoreText.gameObject.SetActive(false);
  48.  
  49. scoreTextB.text = "" + score.ToString();
  50. bestScore.text = "" + Main.instance.GetHighScore();
  51. }
  52.  
  53. public void BirdScored()
  54. {
  55. if (gameOver == true)
  56. return;
  57. else if (gameOver == false)
  58. {
  59. score++;
  60. scoreText.text = "Score: " + score.ToString();
  61. }
  62. }
  63.  
  64. public void restartGame()
  65. {
  66. restart = true;
  67. if(gameOver == true && restart == true)
  68. {
  69. AdsManager.instance.showVideo();
  70. }
  71. }
  72.  
  73. public void MainMenu()
  74. {
  75. mainMenu = true;
  76. if (gameOver == true && mainMenu == true)
  77. {
  78. AdsManager.instance.showVideo();
  79. }
  80. }
  81.  
  82. public void LoadLevel()
  83. {
  84. if(gameOver == true && restart == true)
  85. {
  86. SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
  87. }
  88. else if(gameOver == true && mainMenu == true)
  89. {
  90. SceneManager.LoadScene("Main");
  91. }
  92. }
  93.  
  94. public void pauseGame()
  95. {
  96. Time.timeScale = 0;
  97. paused = true;
  98.  
  99. pauseBtn.gameObject.SetActive(false);
  100. playBtn.gameObject.SetActive(true);
  101. }
  102.  
  103. public void continueGame()
  104. {
  105. if (paused == true)
  106. {
  107. Time.timeScale = 1;
  108. playBtn.gameObject.SetActive(false);
  109. pauseBtn.gameObject.SetActive(true);
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement