FYP - Trials of Chaos: Wave Manager
Introduction
Hi, Welcome back to my blog. My name is Joshua Mootoo and in todays post i will be going into detail about the enemy Wave Manager.
What I Wanted For The Wave Manager
For the Wave Manager i wanted it to be similar to the wave system in Vampire Survivors where the enemies infinitely spawn and have the wave progress to the next after a minute. i also wanted to keep the randomness of the game having it so that the enemy for each wave is different for each run of the game. what i also wanted was certain enemies to be selected on certain waves.
my strugles with the Wave Manager
As i wanted to have it so the wave count increments by 1 after a minute i implemented a timer that adds “Time.deltaTime” as the game goes on. the first problem i ran into is that as a minute passed instead of increasing the wave count by 1 once it would continuously increase.
What I Came Up With plus Solutions
To start off with i made a Wave Class to manage all the variables for each wave like enemy types array, total enemy cap, the different multipliers for the enemies (Health, Damage and Speed). this can be seen below
public class Wave { [NonSerialized]public int enemyNum; public GameObject[] enemyPrefabs; public GameObject bossPrefab; public float healthMultiplier; public float damageMultiplier; public float speedMultiplier; public int enemyCount; public int bossCount; public bool isBossAlive; }
As i wanted the enemy to be chosen at random for the wave i had it so that at the beginning of the wave, the enemy type is randomly selected and that is the enemy that is used for the rest of the wave. i also decided to keep the boss prefab separate as i planned to have both normal enemies and boss enemies in the same wave.
The reason i created the wave class is to make an array of that wave class allowing me to set the variables of each wave as shown in the image below.
I initially had the Game Timer function inside the Wave Manager but decided to move it to the Game Manager Script as other scripts would be accessing the Game Timer. my work around for the wave incrementation was resetting the game timer back to 0 but also keeping track of the minutes/hours as separate float variable. this in turn fixed my constant increase of the wave count
public bool isTimerRunning; public float timer; public int hours; public int minutes; private void TimerUpdate() { if (isTimerRunning) { timer += Time.deltaTime; if (timer >= 60) { timer -= 60; minutes++; } if (minutes >= 60) { minutes -= 60; hours++; } } }
overall i feel that i might make some changes allowing it to be an infinite amount of waves instead of the set waves or have both options but for now i am happy with the state of the Wave Manager.