Best way to speed up a flashing block?

What I’m trying to do is have a block flash on and off but do so faster and faster. Then when it gets to a certain speed flash at that speed for a small while then explode.

I’ve approached this two ways. One with using yield return new WaitForSeconds and making a set number of those until I got to the speed I wanted. But that looks really messy and doesn’t feel very efficient to me. The second approach was to use if statements and a counter count down with a boolean toggling on and off. That felt a bit messy as well but would’ve worked, just as the WaitForSeconds would’ve worked, but required a bit too many if statements in my opinion.

Does anyone figure a more efficient way to go about this?


You could also have a timeout value in Update:

var lastTime = 0;
var speed = 5;
var acceleration = .2;
var tooFast = 1;

function Update()
  if (Time.time - lastTime > speed)
    lastTime = Time.time;
    speed -= acceleration;
    if (speed <= tooFast)