Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- using DG.Tweening;
- public class GameController : MonoBehaviour {
- public bool isGameOver;
- public Canvas VRGameOverCanvas;
- public Text VRGameOverTxt;
- public Text VRScoreTxt;
- public Canvas GameMenu;
- public Text MainMenu;
- private PlayMusic playMusic;
- private float fastFadeIn = .01f;
- public GameObject health;
- public Slider essenceBar;
- public int hp = 3;
- // public GameObject gameOverbutton;
- private int _currScore;
- private int _scoreToWin = 20;
- private bool _didIWin;
- /// <summary>
- /// Start a new game.
- /// </summary>
- public void NewGame() {
- ResetGame();
- }
- void Update()
- {
- if(Input.GetButtonDown("Fire1") && isGameOver)
- {
- ResetGame();
- }
- }
- /// <summary>
- /// Got an enemy! Increment the score and see if we win.
- /// </summary>
- public void GotOne() {
- _currScore++;
- VRScoreTxt.text = "" + _currScore;
- // if (_currScore >= _scoreToWin) {
- // GameOver(true);
- // }
- }
- /// <summary>
- /// Game's over.
- /// </summary>
- /// <param name="didIWin">Did the playeer win?</param>
- public void GameOver(bool didIWin) {
- isGameOver = true;
- _didIWin = didIWin;
- string finalTxt = (_didIWin) ? "You won!" : "Too bad";
- if (GvrViewer.Instance.VRModeEnabled) {
- VRGameOverCanvas.enabled = true;
- VRGameOverTxt.text = finalTxt;
- }
- }
- /// <summary>
- /// Resets the interface, removes remaining game objects. Basically gets us to a point
- /// where we're ready to play again.
- /// </summary>
- public void ResetGame() {
- // Reset the interface
- VRGameOverCanvas.enabled = false;
- isGameOver = false;
- _currScore = 0;
- hp = 3;
- VRScoreTxt.text = "--";
- essenceBar.value = 1000;
- health.transform.GetChild(0).gameObject.SetActive (true);
- health.transform.GetChild(1).gameObject.SetActive (true);
- health.transform.GetChild(2).gameObject.SetActive (true);
- // Remove any remaining game objects
- GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
- foreach (GameObject enemy in enemies) {
- Destroy(enemy);
- }
- }
- void Start () {
- StartCoroutine (UIAnimation ());
- MainMenu.text = "QRays";
- }
- IEnumerator UIAnimation()
- {
- while(true)
- {
- health.transform.DOPunchScale (new Vector3 (.5f, .5f), 1.0f, 5, .5f);
- essenceBar.transform.DOPunchScale (new Vector3 (.5f, .5f), 1.0f, 5, .5f);
- yield return new WaitForSeconds (5f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement