First post and a noob question: How can I get a timer to count down when the mouse is inactive?
I’m working on a public presentation, an architectural visualization, where people can walk around in a building and I want the presentation to reset when nobody is using it. I’ve searched the forums and it’s probably very simple, but I can’t find/figure out how to do it.
Here’s what I have so far, but it only detects mouse clicks (?):
var e : Event = Event.current;
if (e.isMouse){
timer=60;
Debug.Log("Nollställde"+ timer);
}
if (!e.isMouse){
timer=timer-1;
Debug.Log("Räknar ned"+ timer);
}
basically, you hold a timer for that last mouse event. Then just do some math that says Time.time-lastEvent>3000 (3 seconds) then reinitialize the screen.
// from reference:
function OnGUI() {
var e : Event = Event.current;
if (e.isMouse){
Debug.Log("Detected a mouse event!");
}
}
Aerozo: Greatm, thanks! That put me on the right track.
BigMisterB: Thanks for the answer. That’s where I got the code in my first post, but event.isMouse doesn’t seem to register movement without a mouse button being pressed (or maybe it just reatcs to the click alone). It could of course be something else that I’ve missed.