Max Speed Test

I’m creating a simple script that will create a random range of max speed at start and then increment per second the speed of the game object until it reaches max speed. I will use a while loop to make this work since it requires a coroutine!

Start with your current speed and a max speed. Use random.range to setup your max speed.

In a while loop, we will first check if the current speed is less than max speed. We will then wait 1 second and add 5 to the speed then shoot out a debug.log. If we don’t break, we will create an infinite loop. We then need to add an end condition — the break, when the current speed will exceed max speed.

Finally, add startcoroutine into the start section and you are set to go.