This repository has been archived on 2026-04-30. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
monsterstalker/Assets/Scripts/GameController.cs
T
2018-04-10 23:53:49 +10:00

39 lines
799 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GameController : MonoBehaviour {
public Text timerText;
public Text scoreText;
void Awake() {
PersistentData.timer = 60;
PersistentData.score = 0;
StartCoroutine (DecreaseTick ());
}
void Update() {
if (Input.GetButtonDown ("Quit")) {
Application.Quit ();
}
if (PersistentData.timer <= 0) {
SceneManager.LoadScene ("gameover");
}
//update the texts
timerText.text = "Time Remaining: " + PersistentData.timer;
scoreText.text = "Score: " + PersistentData.score;
}
IEnumerator DecreaseTick() {
while (PersistentData.timer > 0) {
yield return new WaitForSeconds (1);
PersistentData.timer -= 1;
}
}
}