I’ve tried to log into the answers section of this website, but it says something about an internal error so I’m posting here.
EDIT: I have solved my issue almost immediately after posting this thread. I’m sorry for posting this thread when I didn’t need to. I have been looking for this issue for the longest time. It turned out that my int value spawnDelay wasn’t actually being initialized in the start function. I looked at the code here in the thread that I posted and I noticed that I had to edit the start function and it didn’t tick in my head until now. I added “spawnDelay = 3;” in the start function. The reason it wasn’t working was because spawnDelay wasn’t initialized, and I wasn’t getting any errors from it. Strange… Oh well. Problem solved
I’m having a game breaking issue where my WaitForSeconds isn’t working in my function in my while loop. My other waitforseconds work just fine outside of the while loop in the same function. so enough talking here is my syntax:
public int spawnDelay;
void Start() {
spawnDelay = 3;
StartCoroutine(spawn());
}
private IEnumerator spawn() {
// stuff happens here
// Spawn loop //
while (true) {
// Stuff happens here
if(enemies.Length < spawnCount) {
spawnEnemy(enemyPath, range, enemyHealth, enemyDamage, enemySpeed);
}
Debug.Log("delay started"); // Instead of being fired slowly.
// This is fired once every frame.
// THIS IS WHAT ISN'T WORKING
yield return new WaitForSeconds(spawnDelay);
Debug.Log("delay ended"); // Instead of being fired slowly.
// Again, this is fired once every frame.
}
}
Note: There is ONLY ONE reference to this function which is in the start function. There is NOT an update function referencing this script. I’m using VS 2015 as my IDE and it only shows one reference to this function which is coming from its own start function.