I find yield WaitForSeconds in Javascript understandable, but when it comes to C# it’s quite confusing.
I have an enemy spawner script that I made in Javascript originally, but want to convert to C#.
function SpawnEmemies() {
yield WaitForSeconds(initialDelay);
for (var i : int = 0; i < waves; i++) {
for (var j : int = 0; j < enemies; j++) {
Instantiate(enemy, transform.position, Quaternion.identity);
yield WaitForSeconds(timeBetweenEnemies);
}
yield WaitForSeconds(timeBetweenWaves);
}
}
I found this solution more elegant than working on time buffers in the Update function. However, how would this look in C#? The main difference I noticed is that in Javascript the code actually waits after a yield WaitForSeconds, while in C# it just continues, and you have to start messing around with Coroutines and what not.