- Home /
Question by
fandi_a · Jun 04, 2013 at 05:36 PM ·
inputeventeventlistener
EventListener for Input class, is there any way to do so?
Hi I'm new to Unity3D, so please pardon if I miss something on the documentation.
Example scenario would be to change this code:
var mouseScrollWheel : float = 0.0;
function processMouseScrollWheelValue1 () {
// code
}
/*
function processMouseScrollWheelValue2 () {
if (mouseScrollWheel != 0) {
// code
}
}
*/
function Update () {
mouseScrollWheel = Input.GetAxis ("Mouse ScrollWheel");
if (mouseScrollWheel != 0) {
processMouseScrollWheelValue1 ();
}
// or
/*
processMouseScrollWheelValue2 ();
*/
}
with something similar to:
function Start () {
Input.addEventListener ("Mouse ScrollWheel", processMouseScrollWheelValue);
}
function processMouseScrollWheelValue (e) {
// code
}
function Update () {
// code unrelated to Input
}
I'm not saying that it will improve the performance. However, I have an opinion that, if you put it on programmer's point of view, it will save a heapload of time for other programmer / team member to scan, read, and refactors the code.
I wonder if there's any way to register event listener to Input class? Or similar.
Comment
Answer by Jessy · Jul 06, 2013 at 08:12 PM
You can't do it with that language you posted in.
http://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx