I understand that I can get the state of the button press using GetButtonDown/Up and the like as per the Unity script manual and stick it in an Update(). However, this solution seems very inefficient because every frame it is executing code to check if the button is pressed or not.
Ideally, an event should be fired when a button is pressed and all I would need to do is to listen to that event and execute my code accordingly.
Does anyone know if this is possible in Unity? if so, how?
It is not possible unless you abstract out the functionality you’re talking about into events you declare yourself, which is easier to use, but won’t do anything to aid performance. This is standard procedure with Unity; there are tons of “Messages” for which a MonoBehaviour can implement code.
Okay, I see. Yep, the messages i'm looking for are related to ButtonDown or ButtonUp. But Unity hasn't added those yet. I hope they implement this in the future. Thanks for your answer.
Also, I’ve been learning to use NGUI and it has a listener class with so called Delegates. I am at the bottom of a complicated mountain, looking up, but this NGUI feature seemed similar to your concept of efficient. I wish I understood it better and why/when I would use it.
Thanks for the answer @paulygons. The NGUI class you linked is not what I'm after because the class serves as a listener to events happening on a game object. What I'm after is an event system that is listening to Input buttons similar to Input.GetButton() but without needing to have it in an Update().
Okay, I see. Yep, the messages i'm looking for are related to ButtonDown or ButtonUp. But Unity hasn't added those yet. I hope they implement this in the future. Thanks for your answer.
– _Shockwave