Greater Than breaks script

I have a script that when the players collects X amount of objects, new objects spawn. It will not work with “>” or “>=”. It gives no errors, the Debug.Log doesn’t update with the score, as if Spawn doesn’t even run. But wait, there’s more. If I use “<” then the script works as expected, except, of course, opposite of what I want.


void Spawn(){
		if (playerScore.score > 5){
		Instantiate(obj[Random.Range(0, obj.GetLength(0))], transform.position, Quaternion.identity);
		Invoke("Spawn", Random.Range (spawnMin, spawnMax));

The problem is that you are doing your Invoke() inside your ‘if (playerScore.sore > 5)’ clause. The first time Spawn is called, if the playerScore.score is not greater that ‘5’, then the Invoke() is not executed and ‘Spawn()’ is never called again. If you move your Invoke down a line outside of the if() clause, your code should work.

Also consider turning this into a coroutine rather than a chained Invoke().