uurha

Untitled

Jan 25th, 2022 (edited)
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class SpawnAndDestroy : MonoBehaviour
  7. {
  8.     public Transform player;
  9.     public GameObject[] obstacle;
  10.     public GameObject[] trees;
  11.     public GameObject clouds;
  12.     public GameObject[] enemies;
  13.     public GameObject[] enemiesMedium;
  14.     public GameObject grounds;
  15.  
  16.     public float height;
  17.     public float heightTrees;
  18.     private float heightClouds;
  19.     public float heightCloudsMin;
  20.     public float heightCloudsMax;
  21.     public float heightGrounds;
  22.     public float heightGroundsMin;
  23.     public float heightGroundsMax;
  24.  
  25.     public Vector2 vector;
  26.  
  27.     public float periodEnemy;
  28.     public float AccelerateEnemy;
  29.     public float periodEnemyMedium;
  30.     public float AccelerateEnemyMedium;
  31.     public float periodClouds;
  32.     public float AccelerateClouds;
  33.     public float periodTrees;
  34.     public float AccelerateTrees;
  35.     public float periodGrounds;
  36.     public float AccelerateGrounds;
  37.  
  38.     private float TimerEnemy;
  39.     private float TimerEnemyMedium;
  40.     private float TimerClouds;
  41.     private float TimerTrees;
  42.     private float TimerGrounds;
  43.  
  44.     public float distanceEnemy;
  45.     public float distanceEnemyMedium;
  46.     public float distanceClouds;
  47.     public float distanceTrees;
  48.     public float distanceRandomTrees;
  49.     public float distanceRandomEnemy;
  50.     public float distanceGrounds;
  51.     public float alive;
  52.  
  53.     private float addPos = 0f;
  54.  
  55.     public float Timer;
  56.  
  57.     public bool goMedium = false;
  58.  
  59.  
  60.      void Medium()
  61.     {
  62.        if(Time.time > Timer)
  63.         {
  64.             goMedium = true;
  65.         }
  66.  
  67.     }
  68.  
  69.     void Awake()
  70.     {
  71.         ///START SPAWN///
  72.         for (int i = 0; i < 20; i++)
  73.         {
  74.             heightClouds = Random.Range(heightCloudsMin, heightCloudsMax);
  75.            GameObject clone =  Instantiate(clouds, vector = new Vector2(Random.Range(10f, 70f), heightClouds), Quaternion.identity);
  76.             Destroy(clone, 20);
  77.         }
  78.  
  79.         for (int i = 0; i < 4; i++)
  80.         {
  81.             distanceRandomTrees = Random.Range(0f, 2f);
  82.             addPos += 10f;
  83.             GameObject clone = Instantiate(trees[Random.Range(0,trees.Length)], vector = new Vector2(addPos + distanceRandomTrees, heightTrees), Quaternion.identity);
  84.             Destroy(clone, 10);
  85.         }
  86.         for (int i = 0; i < 50; i++)
  87.         {
  88.             GameObject clone = Instantiate(grounds,
  89.             vector = new Vector2(Random.Range(10f,60f), heightGrounds = Random.Range(heightGroundsMin, heightGroundsMax)), Quaternion.identity);
  90.             Destroy(clone, alive);
  91.         }
  92.         ///START SPAWN///
  93.  
  94.     }
  95.  
  96.  
  97.     void FixedUpdate()
  98.     {
  99.         Medium();
  100.  
  101.         ///Timers///
  102.         if (Time.time > TimerEnemy)
  103.         {
  104.             if(alive > 3f)
  105.             alive -= 0.05f;
  106.  
  107.             TimerEnemy += periodEnemy;
  108.  
  109.             if (periodEnemy > 1f)
  110.             {
  111.                 if(goMedium)
  112.                     AccelerateEnemy = AccelerateEnemy * 5f;
  113.                
  114.                
  115.                     periodEnemy += AccelerateEnemy;
  116.             }
  117.             SpawnEnemy();
  118.             distanceRandomEnemy = Random.Range(1f,5f);
  119.         }
  120.  
  121.         if (Time.time > TimerEnemyMedium)
  122.         {
  123.             if (alive > 3f)
  124.                 alive -= 0.05f;
  125.  
  126.             TimerEnemyMedium += periodEnemyMedium;
  127.  
  128.             if (periodEnemyMedium > 1f)
  129.                 periodEnemyMedium -= AccelerateEnemyMedium;
  130.             if(goMedium)
  131.             SpawnEnemyMedium();
  132.  
  133.             distanceRandomEnemy = Random.Range(1f, 2f);
  134.         }
  135.  
  136.         if (Time.time > TimerClouds)
  137.         {
  138.             TimerClouds += periodClouds;
  139.  
  140.             if(periodClouds > 0.15f)
  141.             periodClouds -= AccelerateClouds;
  142.  
  143.             SpawnClouds();
  144.             heightClouds = Random.Range(heightCloudsMin, heightCloudsMax);
  145.         }
  146.  
  147.         if (Time.time > TimerTrees)
  148.         {
  149.             TimerTrees += periodTrees;
  150.  
  151.             if(periodTrees > 0.15f)
  152.             periodTrees -= AccelerateTrees;
  153.  
  154.             SpawnTrees();
  155.             distanceRandomTrees = Random.Range(0f,2f);
  156.         }
  157.         if (Time.time > TimerGrounds)
  158.         {
  159.             TimerGrounds += periodGrounds;
  160.  
  161.             heightGrounds = Random.Range(heightGroundsMin, heightGroundsMax);
  162.             if(periodGrounds > 0.01f)
  163.             periodGrounds -= AccelerateGrounds;
  164.  
  165.             SpawnGrounds();
  166.         }
  167.         ///Timers///
  168.     }
  169.  
  170.     ///SPAWNERS UPDATE///
  171.     public void SpawnEnemy()
  172.     {
  173.         GameObject clone = Instantiate(enemies[Random.Range(0, enemies.Length)],
  174.             vector = new Vector2(player.position.x + distanceEnemy + distanceRandomEnemy, height + Random.Range(0f, 0.3f)), Quaternion.identity);
  175.         Destroy(clone, alive);
  176.        
  177.     }
  178.  
  179.     public void SpawnEnemyMedium()
  180.     {
  181.  
  182.         GameObject clone = Instantiate(enemiesMedium[Random.Range(0, enemiesMedium.Length)],
  183.             vector = new Vector2(player.position.x + distanceEnemyMedium + distanceRandomEnemy, height + Random.Range(0f, 0.3f)), Quaternion.identity);
  184.         Destroy(clone, alive);
  185.     }
  186.  
  187.     public void SpawnClouds()
  188.     {
  189.         GameObject clone = Instantiate(clouds, vector = new Vector2(
  190.             player.position.x + distanceClouds, heightClouds), Quaternion.identity);
  191.         Destroy(clone, alive * 3f);
  192.     }
  193.  
  194.     public void SpawnTrees()
  195.     {
  196.         GameObject clone = Instantiate(trees[Random.Range(0, trees.Length)],
  197.             vector = new Vector2(player.position.x + distanceTrees + distanceRandomTrees, heightTrees), Quaternion.identity);
  198.         Destroy(clone, alive);
  199.     }
  200.  
  201.     public void SpawnGrounds()
  202.     {
  203.         GameObject clone = Instantiate(grounds,
  204.             vector = new Vector2(player.position.x + distanceGrounds, heightGrounds), Quaternion.identity);
  205.         Destroy(clone, alive);
  206.     }
  207.     ///SPAWNERS UPDATE///
  208.  
  209. }
  210.  
Add Comment
Please, Sign In to add comment