Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
2,695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class Manager : MonoBehaviour {
  8.  
  9.     public GameObject ninja;
  10.     GameObject[] spawns;
  11.     public float timer;
  12.  
  13.     int spawnCount = 4;
  14.  
  15.     public int cash = 20;
  16.     public int round = 0;
  17.     public GameObject cashUI;
  18.     public GameObject roundUI;
  19.  
  20.     public AudioSource source;
  21.     public AudioClip[] clip;
  22.  
  23.     bool allDead;
  24.  
  25.     // Use this for initialization
  26.     void Start () {
  27.         spawns = GameObject.FindGameObjectsWithTag ("spawn");
  28.         StartCoroutine(Spawn ());
  29.     }
  30.    
  31.     // Update is called once per frame
  32.     void Update () {
  33.         cashUI.GetComponent<Text> ().text = "$" + cash.ToString ();
  34.         roundUI.GetComponent<Text> ().text = "round: " + round.ToString ();
  35.  
  36.         if (GameObject.FindGameObjectsWithTag ("ninja").Length <= 0) {
  37.             allDead = true;
  38.         } else {
  39.             allDead = false;
  40.         }
  41.     }
  42.  
  43.     public void CashIn(int income){
  44.         cash += income;
  45.     }
  46.  
  47.     IEnumerator Spawn(){
  48.        
  49.         round++;
  50.         for (int i = 0; i < spawnCount; i++) {
  51.             yield return new WaitForSeconds (Random.Range (0, 3));
  52.             GameObject mySpawn = spawns [Random.Range (0, spawns.Length)];
  53.             Instantiate (ninja, mySpawn.transform.position, mySpawn.transform.rotation);
  54.         }
  55.         while (allDead != true) {
  56.             yield return null;
  57.         }
  58.         spawns = GameObject.FindGameObjectsWithTag ("spawn");
  59.         spawnCount += 3;
  60.         yield return new WaitForSeconds (timer);
  61.         StartCoroutine(Spawn ());
  62.     }
  63.  
  64.     public void Sound(int num){
  65.         source.PlayOneShot (clip [num]);
  66.         if (num == 2) {
  67.             StartCoroutine (Restart());
  68.         }
  69.     }
  70.  
  71.     IEnumerator Restart(){
  72.         yield return new WaitForSeconds(3.0f);
  73.         SceneManager.LoadSceneAsync (0);
  74.  
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement