Skip to content

Instantly share code, notes, and snippets.

@saturngamesss
Created June 11, 2020 13:15
Show Gist options
  • Save saturngamesss/72d547ecb1ceef5ec9edbc1cbaf67ca6 to your computer and use it in GitHub Desktop.
Save saturngamesss/72d547ecb1ceef5ec9edbc1cbaf67ca6 to your computer and use it in GitHub Desktop.
Basic Wave Spawner for Unity Engine.
//************** REAL GAMES STUDIO ***************
//************************************************
//realgamesss.weebly.com
//gamejolt.com/@Real_Game
//realgamesss.newgrounds.com/
//real-games.itch.io/
//youtube.com/channel/UC_Adg-mo-IPg6uLacuQCZCQ
//************************************************
using System.Collections;
using UnityEngine;
using TMPro;
public class WaveSpawner : MonoBehaviour
{
public TextMeshProUGUI waveCountText;
int waveCount = 1;
public float spawnRate = 1.0f;
public float timeBetweenWaves = 3.0f;
public int enemyCount;
public GameObject enemy;
bool waveIsDone = true;
void Update()
{
waveCountText.text = "Wave: " + waveCount.ToString();
if (waveIsDone == true)
{
StartCoroutine(waveSpawner());
}
}
IEnumerator waveSpawner()
{
waveIsDone = false;
for (int i = 0; i < enemyCount; i++)
{
GameObject enemyClone = Instantiate(enemy);
yield return new WaitForSeconds(spawnRate);
}
spawnRate -= 0.1f;
enemyCount += 3;
waveCount += 1;
yield return new WaitForSeconds(timeBetweenWaves);
waveIsDone = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment