Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class Manager : MonoBehaviour {
- public GameObject ninja;
- GameObject[] spawns;
- public float timer;
- int spawnCount = 4;
- public int cash = 20;
- public int round = 0;
- public GameObject cashUI;
- public GameObject roundUI;
- public AudioSource source;
- public AudioClip[] clip;
- bool allDead;
- // Use this for initialization
- void Start () {
- spawns = GameObject.FindGameObjectsWithTag ("spawn");
- StartCoroutine(Spawn ());
- }
- // Update is called once per frame
- void Update () {
- cashUI.GetComponent<Text> ().text = "$" + cash.ToString ();
- roundUI.GetComponent<Text> ().text = "round: " + round.ToString ();
- if (GameObject.FindGameObjectsWithTag ("ninja").Length <= 0) {
- allDead = true;
- } else {
- allDead = false;
- }
- }
- public void CashIn(int income){
- cash += income;
- }
- IEnumerator Spawn(){
- round++;
- for (int i = 0; i < spawnCount; i++) {
- yield return new WaitForSeconds (Random.Range (0, 3));
- GameObject mySpawn = spawns [Random.Range (0, spawns.Length)];
- Instantiate (ninja, mySpawn.transform.position, mySpawn.transform.rotation);
- }
- while (allDead != true) {
- yield return null;
- }
- spawns = GameObject.FindGameObjectsWithTag ("spawn");
- spawnCount += 3;
- yield return new WaitForSeconds (timer);
- StartCoroutine(Spawn ());
- }
- public void Sound(int num){
- source.PlayOneShot (clip [num]);
- if (num == 2) {
- StartCoroutine (Restart());
- }
- }
- IEnumerator Restart(){
- yield return new WaitForSeconds(3.0f);
- SceneManager.LoadSceneAsync (0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement