Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System;
- public class Spawner : MonoBehaviour {
- public GameObject Bubble;
- GameObject _Bubble;
- public GameObject Fish;
- public GameObject BlueFish;
- public GameObject GoldFish;
- public GameObject Shark;
- public static bool doSpawn = true;
- public static bool doSpawnFish = true;
- public static bool doSpawnBlueFish = true;
- public static bool doSpawnGoldFish = true;
- public static bool doSpawnShark = true;
- float spawnSpeed = 0.25F;
- void Update()
- {
- if(!MainGlobals.isGameOver)
- {
- if (doSpawn)
- {
- StartCoroutine(spawnBubbles());
- }
- if (doSpawnFish)
- {
- StartCoroutine(spawnFishes());
- }
- if (doSpawnBlueFish)
- {
- StartCoroutine(spawnBlueFishes());
- }
- if (doSpawnGoldFish)
- {
- StartCoroutine(spawnGoldFishes());
- }
- if (doSpawnShark)
- {
- StartCoroutine(spawnSharks());
- }
- }
- }
- IEnumerator spawnBubbles()
- {
- doSpawn = false;
- yield return new WaitForSeconds(spawnSpeed);
- spawnBubble();
- doSpawn = true;
- }
- IEnumerator spawnFishes()
- {
- doSpawnFish = false;
- yield return new WaitForSeconds(UnityEngine.Random.Range(3, 7));
- spawnFish();
- doSpawnFish = true;
- }
- IEnumerator spawnBlueFishes()
- {
- doSpawnBlueFish = false;
- yield return new WaitForSeconds(UnityEngine.Random.Range(8, 15));
- spawnBlueFish();
- doSpawnBlueFish = true;
- }
- IEnumerator spawnGoldFishes()
- {
- doSpawnGoldFish = false;
- yield return new WaitForSeconds(UnityEngine.Random.Range(8, 15));
- spawnGoldFish();
- doSpawnGoldFish = true;
- }
- IEnumerator spawnSharks()
- {
- doSpawnShark = false;
- yield return new WaitForSeconds(UnityEngine.Random.Range(8, 15));
- spawnShark();
- doSpawnShark = true;
- }
- public GameObject spawnBubble()
- {
- Vector3 pos = new Vector3(UnityEngine.Random.Range(-3.0F, 3.0F), -6.5F, -5);
- _Bubble = (GameObject)Instantiate(Bubble, pos, Quaternion.identity);
- float bubbleSize = UnityEngine.Random.Range(1.0F, 1.5F);
- _Bubble.transform.localScale = new Vector3(bubbleSize, bubbleSize, _Bubble.transform.localScale.z);
- _Bubble.transform.tag = "bubble";
- return _Bubble;
- }
- public void spawnFish()
- {
- if(_Bubble.transform.childCount <= 0)
- {
- spawnFishes(Fish);
- }
- }
- public void spawnBlueFish()
- {
- if (_Bubble.transform.childCount <= 0)
- {
- spawnFishes(BlueFish);
- }
- }
- public void spawnGoldFish()
- {
- if (_Bubble.transform.childCount <= 0)
- {
- spawnFishes(GoldFish);
- }
- }
- public void spawnShark()
- {
- if (_Bubble.transform.childCount <= 0)
- {
- spawnFishes(Shark);
- }
- }
- public void spawnFishes(GameObject fishType)
- {
- GameObject newFish = (GameObject)Instantiate(fishType, _Bubble.transform.position, Quaternion.identity);
- newFish.transform.SetParent(_Bubble.transform);
- _Bubble.GetComponent<Rigidbody2D>().gravityScale = UnityEngine.Random.Range(-0.03F, -0.5F); ;
- newFish.transform.localScale = _Bubble.transform.localScale / 2;
- if (newFish.transform.position.x > 0)
- {
- newFish.transform.rotation = Quaternion.Euler(0, 180, 0);
- }
- newFish.transform.Rotate(0.0f, 0.0f, UnityEngine.Random.Range(-45.0f, 45.0f));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment