- Home /
Does Unity provide a means to determine the time since the last user interaction?
Title says it all.
I've looked through the docs, but haven't found a function or property that tells you the time since the last user interaction, ( including any/all of mouse movement, mouse clicks, keyboard etc). Does something exist, or do you have to track this yourself?
@Noisecrime, maybe it would help if you explained what you want to do with the information - what's the goal? There may be other, easier ways to achieve it than tracking mouse-clicks.
Its a simple time-out script, i.e when no-one has interacted for a set amount of time, the applications switches to an 'attract' loop. Polling in update will work fine, I just thought it was odd not to find a built in property for it, since it would easily hook into UNity's own code when checking for mouse/keyboard/joystick input.
Answer by qJake · Jun 05, 2010 at 09:20 AM
No, you need to track it yourself, but it should be pretty easy with Input.anyKey
and Input.mousePosition
.
http://unity3d.com/support/documentation/ScriptReference/Input-mousePosition.html
http://unity3d.com/support/documentation/ScriptReference/Input-anyKey.html
You could wrap those into a simple component script that tracked these two values inside of Update(), and you could fire off an event when either/both changed, or you could set a flag (bool) for when there was input or not.
Actually thinking about it mouse movement is pretty irrelevant as you have to click to begin dragging ;) Its straightforward enough to roll my own, trouble is I have several guitextures and colliders that all re-act to mousedown/up events, plus some generic mouseinput checks in update, so that means routing a callback to some centralised object to track input and update the timer. Was just hoping i'd missed something in the docs, since obviously Unity could easily track this itself. thx
Doh, of course as you say a single component script checking for input.Get$$anonymous$$ouseButton() and input.anykey in update() should work just as well and would be much cleaner.
Lots of things that Unity "could" do are not actually included with the editor. I'm not sure why, but my guess is that they want you to code it yourself, but only if you need it. $$anonymous$$eep It Simple, Stupid. :P - http://en.wikipedia.org/wiki/$$anonymous$$eep_it_simple_stupid
Only problem of course is i'm polling mouse input every frame now, but thats not too bad in this case. Whilst I can understand you wouldn't want to put the kitchen sink into Unity, this is pretty basic functionality that should be simple to have, since Unity itself is obviously detecting interaction and routing it to scripts.
@Noisecrime Lots of things in Unity that you would expect to be there "because it would be easy", are not included for the reason I said earlier, and that was because they didn't want to include something unless it was really needed by a lot of people, and couldn't be easily scripted. This property can be very easily scripted with little to no performance impact (if done correctly), so there was no need to add it into Unity, since you can just code it yourself. You'll find lots of "do-it-yourself" scenarios like this one when using Unity. :P
Answer by Ricardo · Jun 05, 2010 at 09:23 AM
There's nothing documented on the Input class to this effect. Moreover, there is no general OnMouseMove, only OnMouseOver for objects with colliders.
That doesn't mean you can't track Input.mousePosition every frame.
Correct. But as his question was oriented towards if Unity provides it, that's what I focused on.
Unfortunately for a lot of these types of questions you have to "guess" at what they really want to hear, even if they don't tell it to you. It's one of the caveats of Stack Overflow sites. :P
Oh, I could guess. :-) I also think that users should be digging into things a bit more themselves, and see it as an antidote for the "everything prepackaged for all possible options" mentality we've been seeing so much of.
At Ricardo - That is Unitys strongest $$anonymous$$arketing point that they try to illustrate in their marketing materials. One shouldn't be surprised to see so many people expecting it. I didn't have to guess at what he wanted either. Taking your guys own advise, if one just thought about the question for a moment I am sure one would figure out what the gentleman was asking. I knew right away, but it was because I was looking for the same thing. ;)
Your answer
Follow this Question
Related Questions
interacting with a raycast 1 Answer
How can I use multiple GetButtonDown keys simultaneously? 2 Answers
Hold down button for in trigger 1 Answer
how to make a highlight gui ?? 1 Answer
Check for any input 1 Answer