- Home /
Can someone explain this?? KeyCode Error
Im working a long time with Unity and i never have seen THIS error and i cant get rid of it no matter what i do...
UnityException: Input Key named: KeyCode.E is unknown UnityEngine.Input.GetKeyDown (string) (wrapper dynamic-method) UnityEngine.Input.Input$GetKeyDown$System.String (object,object[]) Boo.Lang.Runtime.RuntimeServices.Invoke (object,string,object[]) Mouse.Update () (at Assets/Scripts/Mouse.js:9)
basically im getting the "KeyCode.E" from another script so its like Input.GetKey(GameObject.Find(CONTROLS).GetComponent(CONTROLS).forward)
Answer by aldonaletto · Oct 01, 2011 at 06:33 PM
Could GetKey had choosed the wrong version (overload method)? There are two versions, one that accepts strings, and another that expects a KeyCode value. Maybe somewhere in the process the wrong version is choosen, and it causes the error. Try to assign the code to an intermediate variable, like this:
var fwdCode: KeyCode = GameObject.Find(CONTROLS).GetComponent(CONTROLS).forward; ... Input.GetKey(fwdCode)Furthermore, it's more efficient to read the forward code at Start or in other seldomly called function - GameObject.Find is a slow operation, and should not be called in Update or other periodic functions.
Your answer