aboutsummaryrefslogtreecommitdiff
path: root/td/Assets/Scripts/waveSpawner.cs
blob: 73c0bc319118eb4c7882578b71f84f30702ae2dc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class WaveSpawner : MonoBehaviour {
	
	public Transform SpawnPoint;
	public Text WaveCountdownText;
	public float TimeBetweenWaves = 5f;
	[Header("Scripting vars")]
	public Player Player;            // Reference to the player object, should be set in designer

	public static int EnemiesAlive = 0;
	private float _countdown = 2f;
	private int _waveIndex = 0;

	void Update () {
		if (EnemiesAlive > 0) {
			return;
		}

		if (_countdown <= 0f) {
			StartCoroutine(SpawnWave());
			_countdown = TimeBetweenWaves;
			return;
		}

		_countdown -= Time.deltaTime;
		_countdown = Mathf.Clamp(_countdown, 0f, Mathf.Infinity);
		//waveCountdownText.text = string.Format("{0:00.00}", countdown);
	}

	IEnumerator SpawnWave () {
		int waveNum = 1;
		int gdshj = Mathf.FloorToInt(10.64 * (Math.Pow(Math.E, (0.57 * waveNum)))));

		EnemiesAlive = wave.Count;

		for (int i = 0; i < wave.Count; i++)
		{
			SpawnEnemy(wave.Enemy);
			yield return new WaitForSeconds(1f / wave.Rate);
		}

		_waveIndex++;
	}

	void SpawnEnemy (GameObject enemy)
	{
		Instantiate(enemy, SpawnPoint.position, SpawnPoint.rotation);
	}

}