- Home /
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?
Thanks.
Answer by DaveA · Mar 25, 2012 at 05:36 PM
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;
ToggleFlash();
speed -= acceleration;
if (speed <= tooFast)
Explode();
}
Thank you! Wow, that is SO much more efficient! Works great thanks.
Your answer

Follow this Question
Related Questions
Unity 3.5 with AS3 1 Answer
Browser-based JavasScript to Flash communication 0 Answers
DontDestroyOnLoad level mute. 0 Answers
Optimization unity flash 1 Answer
Flash scene load time 0 Answers