- Home /
how to "blink" more often?
if(Time.time % 2 > 1)
{
GUI.DrawTexture(helloRect, picture1);
}
else
{
GUI.DrawTexture(helloRect, picture2);
}
How can I let this "blink" more often?
Answer by Mike 3 · Mar 15, 2011 at 08:22 AM
Something like:
if((Time.time * speed) % 2 > 1)
would be the quickest way to do it
Answer by DaveA · Mar 15, 2011 at 08:26 AM
Time.time is a float, not sure that % 2 of that would ever really be more than 1? Anyway there's a lot of ways to set up timers. I usually do something like this:
var rate = .5; // seconds var lastCheck = 0.0;
Update() { if ((Time.time - lastCheck) >= rate) { Do Something lastCheck = Time.time; } }
which will 'Do Something' every 'rate' seconds. So you could toggle a boolean and pick a texture then. Smaller values of 'rate' will do it faster
$$anonymous$$y Do someting needs to be in the OnGUI, is that possible?
Regarding OnGUI - you'd have to check the time when Event.current.type == EventType.Repaint only