Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class GameController : MonoBehaviour {
- public GameObject enemy;
- public int enemyCount; // 10
- private int score;
- private bool gameOver;
- private bool restart;
- void Awake () {
- score = 0;
- gameOver = false;
- restart = false;
- }
- void Start () {
- StartCoroutine(SpawnWaves ());
- }
- void OnGUI () {
- GUI.Label(new Rect(10, 10, 100, 20), "Score: " + score);
- if (gameOver) {
- GUI.Label(new Rect(Screen.width / 2 - 40, Screen.height / 3, 80, 20), "Game Over!");
- }
- if (restart) {
- if (GUI.Button(new Rect(Screen.width - 70, 10, 60, 20), "Restart")) {
- Application.LoadLevel(Application.loadedLevel);
- }
- }
- }
- IEnumerator SpawnWaves () {
- yield return new WaitForSeconds (1.0f);
- while (true) {
- for (int i = 0; i < enemyCount; i++) {
- Vector3 spawnPosition = new Vector3(Random.Range(-9.0f, 9.0f), 0.0f, 26.0f);
- GameObject clone = Instantiate(enemy, spawnPosition, Quaternion.identity) as GameObject;
- clone.transform.parent = transform;
- yield return new WaitForSeconds (0.5f);
- }
- yield return new WaitForSeconds (3.0f);
- if (gameOver) {
- restart = true;
- break;
- }
- }
- }
- public void AddScore (int newScoreValue) {
- score += newScoreValue;
- }
- public void GameOver () {
- gameOver = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment