Timer counting down when mouse is inactive

Hi.

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);

}

Thanks!

Here you go:

var maxIdleTime : float = 60;

private var timeCount : float = 0;
private var lastMousePos : Vector2 = Vector2.zero;

function Update() {
	if(lastMousePos == Input.mousePosition) {
		timeCount += Time.deltaTime;
		if(timeCount > maxIdleTime) {
			//Perform reset actions here
			timeCount = 0;
		}
	} else
		timeCount = 0;
	
	lastMousePos = Input.mousePosition;
}

P.S. This only a good solution if you wanna reload the level, otherwise it’s just gonna trigger a whole load of events if nobody moves the mouse

checkup on event.isMouse.

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.