SHARE
TWEET

Untitled

a guest Aug 9th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using UnityEngine;
  3.  
  4. public class Opject_Sp : MonoBehaviour
  5. {
  6.  
  7.     public GameObject Player;
  8.     public GameObject Money;
  9.  
  10.     public GameObject BigTree;
  11.     public GameObject[] Rocks;
  12.     public GameObject[] debrees;
  13.  
  14.     private float MoneyTimer = 2.0f;
  15.     private float RockTimer = 2.0f;
  16.     private float BigTreeTimer = 5.0f;
  17.  
  18.     public AudioClip BigRockFalling;
  19.  
  20.     // Update is called once per frame
  21.     void Update()
  22.     {
  23.         MoneyTimer -= Time.deltaTime;
  24.         RockTimer -= Time.deltaTime;
  25.         BigTreeTimer -= Time.deltaTime;
  26.  
  27.         if (MoneyTimer < 0)
  28.         {
  29.             SpawnMoney();
  30.         }
  31.         if (RockTimer < 0)
  32.         {
  33.             SpawnRock();
  34.         }
  35.         if (BigTreeTimer < 0)
  36.         {
  37.             StartCoroutine(SpawnBigTree());
  38.         }
  39.     }
  40.  
  41.     void SpawnMoney()
  42.     {
  43.         GameObject Mon = Instantiate(Money, new Vector2(Random.Range(-6.47f, 6.62f), 6), Quaternion.identity) as GameObject;
  44.         MoneyTimer = Random.Range(0.5f, 2.5f);
  45.     }
  46.  
  47.     void SpawnRock()
  48.     {
  49.         GameObject Roc = Instantiate(Rocks[(Random.Range(0, Rocks.Length))], new Vector2(Random.Range(-7f, 7f), 10), Quaternion.identity) as GameObject;
  50.         RockTimer = Random.Range(0.5f, 2.5f);
  51.         Roc.GetComponent<Rigidbody2D>().gravityScale = Random.Range(1, 3);
  52.     }
  53.     IEnumerator SpawnBigTree()
  54.     {
  55.         BigTreeTimer = 1000;
  56.         Vector2 spawnSpot;
  57.         int debreeTimer = (Random.Range(20, 30));
  58.         int spawnOnPlayerPer = (Random.Range(0, 100));
  59.         if (spawnOnPlayerPer < 50)
  60.         {
  61.             spawnSpot = new Vector2(Random.Range(-7f, 7f), 20);
  62.         }
  63.         else
  64.         {
  65.             spawnSpot = new Vector2(Player.transform.position.x, 20);
  66.         }
  67.         while (debreeTimer > 0)
  68.         {
  69.             debreeTimer--;
  70.             float t = Random.Range(0.005f, 0.1f);
  71.             yield return new WaitForSeconds(t);
  72.             Debug.Log("Spawned");
  73.             GameObject debree = Instantiate(debrees[(Random.Range(0, debrees.Length))], new Vector2(spawnSpot.x + Random.Range(-1.0f, 1.0f), spawnSpot.y -10), Quaternion.identity) as GameObject;
  74.             yield return new WaitForSeconds(1);
  75.             Instantiate(BigTree, spawnSpot, Quaternion.identity);
  76.             BigTreeTimer = Random.Range(30.0f, 45.0f);
  77.         }
  78.         Debug.Log("Complete");
  79.         yield return new WaitForSeconds(1);
  80.         Instantiate(BigTree, spawnSpot, Quaternion.identity);
  81.         Player.GetComponent<AudioSource>().PlayOneShot(BigRockFalling, 3.0f);
  82.         BigTreeTimer = Random.Range(30.0f, 45.0f);
  83.     }
  84. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top