x


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) <IL 0x00001, 0x00023> (wrapper dynamic-method) UnityEngine.Input.Input$GetKeyDown$System.String (object,object[]) <IL 0x0000c, 0x0004c> Boo.Lang.Runtime.RuntimeServices.Invoke (object,string,object[]) <IL 0x0004c, 0x00125> 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)

more ▼

asked Oct 01, 2011 at 06:07 PM

Chesley gravatar image

Chesley
191 75 60 66

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Oct 01, 2011 at 06:33 PM

aldonaletto gravatar image

aldonaletto
56.8k 31 77 291

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x6197
x3365
x93
x55
x33

asked: Oct 01, 2011 at 06:07 PM

Seen: 1410 times

Last Updated: Oct 02, 2011 at 01:10 PM