You want a Coroutine.
// IEnumerator tells Unity to run this as a coroutine
// that can suspend and wait, without stalling the whole game.
IEnumerator Start() {
// Your loop condition was backwards,
// so it would never execute the body.
// It looks like you want a < here instead.
for (int a = 0; a < 1000; a++)
{
Debug.Log("Done!");
// yield return means "suspend this method"
// and the WaitForSeconds tells us when to resume it.
yield return new WaitForSeconds(0.1f);
}
}
An important thing to understand about Unity is that the MonoBehaviour
message methods like Start()
and Update()
are called on the main thread (ie. single-threaded). So if you stall one of them by hitting a long-running loop or sleeping the thread, you cause the entire game to hang.
So, if you want to add a delay, it needs to be by yield
ing control back to the engine temporarily - so it can continue running other update functions, accepting input, rendering frames, etc. - until you are ready to resume your work.