- Home /
how to call event function for keys mono-behaviour C#
I'm trying to make an event that won't be called every frame but ONLY when event happens is it possible? if it's impossible
how to call input so I verify in Update if correct thing was pressed (Forward is dinamic string (it changes dependent on the controlls user set it up)) if it's impossible
is it really the least efficient way calling 60 or more controlls per frame just to walk forward?
and if I have
OnGUI () {}
does it take more process?public string Forward = "W"; void OnKeyDown () { Debug.Log("ehgauebw"); }
void Update () { if (Input.GetKey().ToString == Forward) { Debug.Log("ehgauebw"); } }
void OnGUI (){ if (Event.current.keyCode.ToString() == Forward){ Debug.Log("sdeiflgh"); } }
Answer by Loius · Feb 11, 2013 at 08:14 PM
Check the Scripting Reference. GetKey takes a string or KeyCode argument, Event.current.keyCode is a KeyCode, so you should store your control as a KeyCode.
ah now I get what you mean I'll try
and how do I fetch keycode scroll wheel than I was doing before like this
// we catch $$anonymous$$ouseWheel Forward/Backward
if (e.delta.ToString() == "(0.0, -3.0)"){
$$anonymous$$eys = "scroll Wheel Forward";
DontTurnOffToggle = false;
}
else if (e.delta.ToString() == "(0.0, 3.0)"){
$$anonymous$$eys = "scroll Wheel Backward";
DontTurnOffToggle = false;
}
and than a function key can't be found Print screen
asd is $$anonymous$$eyCode in structure Bind$$anonymous$$ey
if (Input.Get$$anonymous$$ey(bind$$anonymous$$ey.asd)){
Debug.Log("ldjkas");
}
if I set it to any different char I find it if to print screen that can be fetched only with event than I don't find it