Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class SpawnAndDestroy : MonoBehaviour
- {
- public Transform player;
- public GameObject[] obstacle;
- public GameObject[] trees;
- public GameObject clouds;
- public GameObject[] enemies;
- public GameObject[] enemiesMedium;
- public GameObject grounds;
- public float height;
- public float heightTrees;
- private float heightClouds;
- public float heightCloudsMin;
- public float heightCloudsMax;
- public float heightGrounds;
- public float heightGroundsMin;
- public float heightGroundsMax;
- public Vector2 vector;
- public float periodEnemy;
- public float AccelerateEnemy;
- public float periodEnemyMedium;
- public float AccelerateEnemyMedium;
- public float periodClouds;
- public float AccelerateClouds;
- public float periodTrees;
- public float AccelerateTrees;
- public float periodGrounds;
- public float AccelerateGrounds;
- private float TimerEnemy;
- private float TimerEnemyMedium;
- private float TimerClouds;
- private float TimerTrees;
- private float TimerGrounds;
- public float distanceEnemy;
- public float distanceEnemyMedium;
- public float distanceClouds;
- public float distanceTrees;
- public float distanceRandomTrees;
- public float distanceRandomEnemy;
- public float distanceGrounds;
- public float alive;
- private float addPos = 0f;
- public float Timer;
- public bool goMedium = false;
- void Medium()
- {
- if(Time.time > Timer)
- {
- goMedium = true;
- }
- }
- void Awake()
- {
- ///START SPAWN///
- for (int i = 0; i < 20; i++)
- {
- heightClouds = Random.Range(heightCloudsMin, heightCloudsMax);
- GameObject clone = Instantiate(clouds, vector = new Vector2(Random.Range(10f, 70f), heightClouds), Quaternion.identity);
- Destroy(clone, 20);
- }
- for (int i = 0; i < 4; i++)
- {
- distanceRandomTrees = Random.Range(0f, 2f);
- addPos += 10f;
- GameObject clone = Instantiate(trees[Random.Range(0,trees.Length)], vector = new Vector2(addPos + distanceRandomTrees, heightTrees), Quaternion.identity);
- Destroy(clone, 10);
- }
- for (int i = 0; i < 50; i++)
- {
- GameObject clone = Instantiate(grounds,
- vector = new Vector2(Random.Range(10f,60f), heightGrounds = Random.Range(heightGroundsMin, heightGroundsMax)), Quaternion.identity);
- Destroy(clone, alive);
- }
- ///START SPAWN///
- }
- void FixedUpdate()
- {
- Medium();
- ///Timers///
- if (Time.time > TimerEnemy)
- {
- if(alive > 3f)
- alive -= 0.05f;
- TimerEnemy += periodEnemy;
- if (periodEnemy > 1f)
- {
- if(goMedium)
- AccelerateEnemy = AccelerateEnemy * 5f;
- periodEnemy += AccelerateEnemy;
- }
- SpawnEnemy();
- distanceRandomEnemy = Random.Range(1f,5f);
- }
- if (Time.time > TimerEnemyMedium)
- {
- if (alive > 3f)
- alive -= 0.05f;
- TimerEnemyMedium += periodEnemyMedium;
- if (periodEnemyMedium > 1f)
- periodEnemyMedium -= AccelerateEnemyMedium;
- if(goMedium)
- SpawnEnemyMedium();
- distanceRandomEnemy = Random.Range(1f, 2f);
- }
- if (Time.time > TimerClouds)
- {
- TimerClouds += periodClouds;
- if(periodClouds > 0.15f)
- periodClouds -= AccelerateClouds;
- SpawnClouds();
- heightClouds = Random.Range(heightCloudsMin, heightCloudsMax);
- }
- if (Time.time > TimerTrees)
- {
- TimerTrees += periodTrees;
- if(periodTrees > 0.15f)
- periodTrees -= AccelerateTrees;
- SpawnTrees();
- distanceRandomTrees = Random.Range(0f,2f);
- }
- if (Time.time > TimerGrounds)
- {
- TimerGrounds += periodGrounds;
- heightGrounds = Random.Range(heightGroundsMin, heightGroundsMax);
- if(periodGrounds > 0.01f)
- periodGrounds -= AccelerateGrounds;
- SpawnGrounds();
- }
- ///Timers///
- }
- ///SPAWNERS UPDATE///
- public void SpawnEnemy()
- {
- GameObject clone = Instantiate(enemies[Random.Range(0, enemies.Length)],
- vector = new Vector2(player.position.x + distanceEnemy + distanceRandomEnemy, height + Random.Range(0f, 0.3f)), Quaternion.identity);
- Destroy(clone, alive);
- }
- public void SpawnEnemyMedium()
- {
- GameObject clone = Instantiate(enemiesMedium[Random.Range(0, enemiesMedium.Length)],
- vector = new Vector2(player.position.x + distanceEnemyMedium + distanceRandomEnemy, height + Random.Range(0f, 0.3f)), Quaternion.identity);
- Destroy(clone, alive);
- }
- public void SpawnClouds()
- {
- GameObject clone = Instantiate(clouds, vector = new Vector2(
- player.position.x + distanceClouds, heightClouds), Quaternion.identity);
- Destroy(clone, alive * 3f);
- }
- public void SpawnTrees()
- {
- GameObject clone = Instantiate(trees[Random.Range(0, trees.Length)],
- vector = new Vector2(player.position.x + distanceTrees + distanceRandomTrees, heightTrees), Quaternion.identity);
- Destroy(clone, alive);
- }
- public void SpawnGrounds()
- {
- GameObject clone = Instantiate(grounds,
- vector = new Vector2(player.position.x + distanceGrounds, heightGrounds), Quaternion.identity);
- Destroy(clone, alive);
- }
- ///SPAWNERS UPDATE///
- }
Add Comment
Please, Sign In to add comment