- Home /
Input versus Event
Hi,
I am wondering what's the core difference between Input and Event.
In which case should I use Input or Event ? What are their advantage or failing ?
I know that this could lead to a wide discussion but I need some clarifications because I can't find in the documentation any good explanation.
Thanks a lot.
There's a lot to be said for "just don't use Event." But then there's a lot to be said for "Just don't use GUI."
Answer by syclamoth · Sep 18, 2013 at 08:23 AM
Brodaly, 'Event' is used for GUI scripting, and 'Input' is used for game-world controller handling. There is no real discussion about where to use one or the other- they are generally used for fundamentally different things and while there is some overlap in functionality, it rarely comes up in practice.
Can you give me some examples of using Event in a GUI scripting context ?
I initially thought this stuff was well documented in the online scripting reference, but upon closer inspection it seems that either I was wrong, or that the documentation has gotten worse since I last looked it up. In any case, a simple example would be using Event.current.mousePosition
inside of OnGUI in order to find the GUI-space position of the cursor for that event (as opposed to Input.mousePosition
, which uses screen coordinates).
The main difference you must keep in $$anonymous$$d, is that the Input class is essentially a set of static functions for querying the state of controller input for a given frame, and the Event class is used in GUI code to deter$$anonymous$$e what to do in a given pass.
Events are created one at a time, and each event is passed into OnGUI exactly once- you must check Event.current.type
to find out exactly what kind of event it is before using it.
Your answer
Follow this Question
Related Questions
Why am I losing some inputs on Update function? 0 Answers
Emulate RightArrow GUI Event 0 Answers
How do you get Unity to return a user input? 1 Answer
Update - Delaying until next frame? 0 Answers
TextField not clear after focusing it through a Key 1 Answer