So basically the function as created in the lesson doesn’t work. I’m not sure if this gets corrected later, but if you’re confused or struggling to see the speed change this is likely why.
In IncreaseDifficulty Tim is creating a new local variable newSpawnInterval and passing that through. He’s using a public variable spawnInterval and subtracting spawnIntervalDecrease from it. Then he’s assigning that value to newSpawnInterval. Then he’s assigning that value to WaitTime.
The problem is that spawnInterval itself is never changed and newSpawnInterval is recreated every time you use the method.
So the original code starts it at 3 and subtracts 0.1, but it will just restart at 3f - 0.1f every time - because those values never change.
TL;DR: If you want a quick fix, you can do this:
public void IncreaseDifficulty()
{
spawnInterval -= spawnIntervalDecrease;
spawnInterval = Math.Max(spawnInterval, minSpawnInterval);
enemySpawner.WaitTime = spawnInterval;
enemySpawner.Start();
}
This should work properly. Ultimately there’s no reason to use newSpawnInterval because you already have a maxSpawnInterval as an outside value that you can reset to.
Hope this helps!
Final Note: If you’re not sure. You can actually test this by assigning a public variable to the value of newSpawnInterval and then have it print to the screen and update with UpdateUI(). It will always show “2.9” because you’re never actually changing the value.