Take a quick review of how coroutines are implemented in Unity3D. They are actually “subprocesses” almost, so they are used in a slightly different way than you are assuming above. It’s kinda subtle.
In any case, there’s plenty of reference to review on that. I took a moment and rewrote your last two function so that it ought to work properly now:
IEnumerator wave1()
{
print ("wave 1 starting.");
for(int i = 1; i < 10; i++)
{
yield return new WaitForSeconds(sd);
enemySpawn ();
enemySpawn ();
}
}
IEnumerator Start()
{
Instantiate (Player, new Vector2 (0, 0), Quaternion.identity); // spawn player
yield return new WaitForSeconds (5.0f);
yield return StartCoroutine (wave1 ());
}
Note that I deleted and do not use the delay() function.
I would recommend moving the adjustment of the “sd” variable so that it is more explicitly tied to the actual wave controlling loop in wave1(). Otherwise it will be very difficult to keep it “in sync” with how you want the pacing of the game to advance.
You’re welcome! Unity has a very slick “lightweight” system for this sort of pseudo-multitasking that really works nicely, and once you get comfortable with it, you’ll find lots of ways to abuse it, er, I mean use it.