Hey, I'm working on removing as much as possible from Update(), or anything else that ticks like a mo-fo. I wondered if it was possible to read keyboard input that isn't dependent on checking EVERY FRAME if(Input.GetKeyDown) or what ever.
I'm still a n00b, but it seems like that's SUCH a sloppy way to do it. is there some sort of keypress event that I can listen for instead? if not in unity, perhaps in .Net?
I have decided that ticking is for suckers.
Answer by Parthon
Apr 04, 2011 at 06:39 PM
Ticking might seem like it's for suckers at first, but you have to remember that every frame of your game the computer is pumping that scene data to your GPU, then getting it to transform every polygon and paint it on the screen. There's millions of cycles being used to do the same thing over and over 60 times a second.
An if statement in an update function is nothing compared to everything else that's going on.
The alternative is what Eric5h5 said: callbacks on keypress. And like Eric said, callbacks aren't available in Unity. You could wrap the input class in something that emulates callbacks, but you'd still need to put it in a ticker function somewhere.
The input loop is still being used even after decades of game development because it's fast and simple.
Interesting, guys, Thank you both! I'll give you both a check-mark if i could. Ting!
Answer by Eric5h5
Feb 20, 2011 at 09:00 AM
There aren't any input callbacks unfortunately. You have to check every frame (or at least every frame that you're expecting that input can occur).
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
No one has followed this question yet.
Keyboard Input Question
LeftControl key at runtime
Add keyboard input in ClickToMove
How do I check for input that is faster than 1 frame?
Activate an input to pickup or search objectes