Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public GameObject topSpawn, leftSpawn, rightSpawn, bottomSpawn;
- public GameObject spawnLocation;
- public float lastSpawn;
- public float timeBetweenSpawns = 1f;
- public float timeSinceLastSpawnShuffle;
- void Awake()
- {
- GetSpawnLocation();
- }
- void Update()
- {
- lastSpawn = lastSpawn + Time.deltaTime;
- timeSinceLastSpawnShuffle = timeSinceLastSpawnShuffle + Time.deltaTime;
- if (timeSinceLastSpawnShuffle > 10f)
- {
- GetSpawnLocation();
- }
- }
- public void GetSpawnLocation()
- {
- float spawnLocationChance = Random.value;
- if (spawnLocationChance >= 0 && spawnLocationChance < 0.25)
- {
- spawnLocation = topSpawn;
- }
- if (spawnLocationChance >= 0.25 && spawnLocationChance < 0.50)
- {
- spawnLocation = rightSpawn;
- }
- if (spawnLocationChance >= 0.50 && spawnLocationChance < 0.75)
- {
- spawnLocation = bottomSpawn;
- }
- if (spawnLocationChance >= 0.75 && spawnLocationChance < 1.00)
- {
- spawnLocation = leftSpawn;
- }
- }
- void SpawnEnemies()
- {
- if (lastSpawn > timeBetweenSpawns && enemiesSpawned < enemiesToSpawn)
- {
- if (spawnLocation == topSpawn || spawnLocation == bottomSpawn)
- {
- GameObject enemy = Instantiate (enemy, (spawnLocation.transform.position + new Vector3 (Random.Range(-20, 20), 0, 0)), Quaternion.identity) as GameObject;
- lastSpawn = 0;
- }
- if (spawnLocation == leftSpawn || spawnLocation == rightSpawn)
- {
- GameObject enemy = Instantiate (enemy, (spawnLocation.transform.position + new Vector3 (0, 0, Random.Range(-20, 20))), Quaternion.identity) as GameObject;
- lastSpawn = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement