Is there a function call when someone presses a button? Or is that only manageable inside up update() ?
I don’t know of one natively. It’s not uncommon to have an input manager of sorts.
SO I guess tagging an Input manager function call on update is the only bet?
No, here’s a list of all the unity-called functions: Unity - Scripting API: MonoBehaviour
(Under “Overridable Functions”)
As you can see, the only Input related functions are part of the mouse activity. You’ll have to do your own input management if you’re trying to use keyboard, controller, or device input.
I won’t commit to saying it’s the only bet, but it’s probably a decent one, particularly for multi-platform support.
Cheers for everyone’s responses. I’ll just make my own that calls from the update function. Hopefully that won’t affect things too much. Cheers.
OnInput wouldn’t make sense as it wouldn’t work well with mosue etc.
normally you use Update or a coroutine with yield return null and then check there the Input class (or you use events but that has pros and cons)
That’s true, but perhaps an onInput for keys only. like. OnKey() to be more straight forward
Direct input event handing does not make much sense in game code. Games run in a constant cycle of maintaining simulations, running game code and pushing frames for rendering. Input handling only makes sense in the game code step, that is within Update.
Any input events caught during the other steps of the cycle couldn’t be used before the game code step anyway, which is why they are cached by the engine until you access the info in Update. So the only sensible implementation of an OnInput event from engine side would be exactly the same as the one you are now implementing.
You may then argue that if it is as simple as that to set this up, we should have it in. However that is the case for a lot of currently non-existing API. The goal of the API is to either provide easy access to complex functionality or support commonly used workflows. This case matches neither.