Why this script crashes Unity

Hi, I’ve been working on a spawning script to end up spawning enemies/ asteroids with the intention of making them spawn faster (so after 10 seconds there’s a spawn, then after 9 seconds another spawn and 8 etc.) but I haven’t been able to get the code to work and now I can’t find errors in the script but it’s crashing Unity when ran. I think it could be something to do with the loop or time algorithms.

Any help on this would be greatly appreciated, thanks!

Also any of the comments in the code are mainly just for testing purposes.

Don’t use goto statements. Use while loops with a breaking condition, do use InvokeRepeating and Coroutines to manage repeated events with timers, your goto statement probably has untended affects we can’t account for in this small script, but the implementation will and is leading to poor results.

I do realize you have a constraint on execution using the timer greater than timerMax if statement, but this can be updated to use coroutines instead. No other issues seem to pop out from looking at your script. Though on line 93 you will probably want to adjust to use Quaternion.identity instead of a parameterless constructor which will indicate no rotation.

Instantiate(LargeAsteroid, AsteroidPos, Quaternion.identity);