Created
June 11, 2020 13:15
-
-
Save saturngamesss/72d547ecb1ceef5ec9edbc1cbaf67ca6 to your computer and use it in GitHub Desktop.
Basic Wave Spawner for Unity Engine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//************** 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