Hi, i'm very new to unity, and as such, i was gonna make a basic demo, just to increase my skills, it should make the player capable of picking up certain items, and activating others, etc. etc.
Now, the key i used for picking up items was the 'E' key, like in many FPS. Being new, i just edited the "FPSWalker" script, which is a build-in, at least in my version of unity.
When testing and all that, it executed just fine, everything worked. I then tried to build it, and run it, and now the 'E' key seemed to only pick up the items once in a while. I then added the line: MoveDirection.y=jumpSpeed as a consequence for pressing the 'E' key, and still it only jumped sometimes, no saying when. The strange thing is still that in the unity editor, it all works fine, but as soon as i build it, the 'E' key only reacts sometimes, while any other key in the game (Which was already written in the build-in-script, not by me), works perfectly, and no lag is present, so it can't be any of those options, my script is as following:
It's because you're reading it in FixedUpdate. You should probably move the section of code relating to jumping to the Update function.
This is because GetKeyDown is true only for that frame where the key is pressed, so it's inherently linked to the frame rate (and therefore the framerate-based "Update()" function) rather than the physics-engine-based "FixedUpdate()" function. As a result, KeyDown or KeyUp input readings can be missed if you use it in FixedUpdate. The degree or frequency to which they're missed will be related to the framerate, so that is probably why you're seeing a difference between the performance in the editor compared with the built version.
answered Mar 14 '10 at 12:32 PM