Is there a way to get the exact time of an input event?
GetKeyDown would be true for the first frame the user pressed a button, but event itself happened slightly before this (most likely)
I am also interested in this topic,
i didn’t test it but this was the best thread with a solution:
-please respond if you were successful
another discussion:
http://forum.unity3d.com/threads/54154-Realtime-input-in-Unity
one may ask: if you change things during Update, why would you need a more precise Input Handling?
lets take this for example, who first presses a button after the signal wins:
based on frame rate, hits within the same 15ms(60fps) of a frame would be equal, thats totally achievable
I was considering a similar approach i.e. polling. I was going to do this either in FixedUpdate() with a high frequence (200 per second) or with a coroutine.
The FixedUpdate() works if you don’t use it for anything else. I haven’t tried the coroutine approach yet.
InvokeRepeating would probably also do the trick.
Time.time will give you the time (since game start) of the input event Unity - Scripting API: Time.time
As for slightly before, you cannot do anything because nobody invented a time machine yet. The best you can do is to use that mind reading device to shortcut the keyboard.
ivkoni asked specifically, “Is there a way to get the exact time of an input event?”
What he means is that he wants to get the “Exact” time that the event happened, not the Upate past it, or the FixedUpdate past it. Where as you can never get the exact point something happened. you can get it at a point close enough to matter.
Update happens after every frame. FixedUpdate happens about every 0.02 seconds. We want it faster…
InvokeRepeating(myFunction, 0.001)
This will get an event as it happens every 1,000 of a second.
The question is valid if you are trying to make a game where you judge reaction time.