Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. using DG.Tweening;
  5.  
  6. public class GameController : MonoBehaviour {
  7.  
  8.  
  9. public bool isGameOver;
  10.  
  11.  
  12. public Canvas VRGameOverCanvas;
  13. public Text VRGameOverTxt;
  14.  
  15. public Text VRScoreTxt;
  16.  
  17. public Canvas GameMenu;
  18. public Text MainMenu;
  19. private PlayMusic playMusic;
  20. private float fastFadeIn = .01f;
  21.  
  22. public GameObject health;
  23. public Slider essenceBar;
  24.  
  25. public int hp = 3;
  26.  
  27.  
  28.  
  29. // public GameObject gameOverbutton;
  30. private int _currScore;
  31. private int _scoreToWin = 20;
  32. private bool _didIWin;
  33.  
  34. /// <summary>
  35. /// Start a new game.
  36. /// </summary>
  37. public void NewGame() {
  38. ResetGame();
  39. }
  40.  
  41. void Update()
  42. {
  43. if(Input.GetButtonDown("Fire1") && isGameOver)
  44. {
  45. ResetGame();
  46. }
  47.  
  48.  
  49. }
  50.  
  51.  
  52. /// <summary>
  53. /// Got an enemy! Increment the score and see if we win.
  54. /// </summary>
  55. public void GotOne() {
  56. _currScore++;
  57.  
  58.  
  59. VRScoreTxt.text = "" + _currScore;
  60. // if (_currScore >= _scoreToWin) {
  61. // GameOver(true);
  62. // }
  63. }
  64.  
  65. /// <summary>
  66. /// Game's over.
  67. /// </summary>
  68. /// <param name="didIWin">Did the playeer win?</param>
  69.  
  70. public void GameOver(bool didIWin) {
  71. isGameOver = true;
  72. _didIWin = didIWin;
  73. string finalTxt = (_didIWin) ? "You won!" : "Too bad";
  74. if (GvrViewer.Instance.VRModeEnabled) {
  75. VRGameOverCanvas.enabled = true;
  76. VRGameOverTxt.text = finalTxt;
  77. }
  78.  
  79. }
  80. /// <summary>
  81. /// Resets the interface, removes remaining game objects. Basically gets us to a point
  82. /// where we're ready to play again.
  83. /// </summary>
  84. public void ResetGame() {
  85. // Reset the interface
  86. VRGameOverCanvas.enabled = false;
  87.  
  88. isGameOver = false;
  89. _currScore = 0;
  90. hp = 3;
  91.  
  92. VRScoreTxt.text = "--";
  93. essenceBar.value = 1000;
  94.  
  95. health.transform.GetChild(0).gameObject.SetActive (true);
  96. health.transform.GetChild(1).gameObject.SetActive (true);
  97. health.transform.GetChild(2).gameObject.SetActive (true);
  98. // Remove any remaining game objects
  99. GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
  100. foreach (GameObject enemy in enemies) {
  101. Destroy(enemy);
  102. }
  103.  
  104. }
  105.  
  106. void Start () {
  107. StartCoroutine (UIAnimation ());
  108. MainMenu.text = "QRays";
  109.  
  110. }
  111. IEnumerator UIAnimation()
  112. {
  113. while(true)
  114. {
  115. health.transform.DOPunchScale (new Vector3 (.5f, .5f), 1.0f, 5, .5f);
  116. essenceBar.transform.DOPunchScale (new Vector3 (.5f, .5f), 1.0f, 5, .5f);
  117.  
  118. yield return new WaitForSeconds (5f);
  119. }
  120. }
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement