- Home /
Is it possible to erase previously pressed key on Unity 2d ?
I have two object in my game called "Cell1" and "Cell2".I also have a script that will trigger a narration or dialog box if I pressed a certain button (in my case , it's the "f" key) and if my character is within the range of either "Cell1" and "Cell2".
I pressed that key for the first time in range of "Cell1" and a narration appeared , however here's the problem.
When my character is within the range of "Cell2" , the narration just triggered without me pressing the "F" button for the second time.
After looking at my codes , it would seem that Input.GetKey(KeyCode.F) thought that I have pressed the F key before (at my first pressing) , so the compiler just keep running it , even though I didn't pressed the F key for the second time.
What I am saying , is Unity reading my input history , and if so is it possible to erase it ?
The Asset I am using is below : https://www.assetstore.unity3d.com/en/#!/content/47062
Many Thanks.
You should probably use Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.F)
for this ins$$anonymous$$d. Input.Get$$anonymous$$ey($$anonymous$$eyCode.F)
is going to be called multiple times when F is pressed so may result in skipping multiple dialogue boxes with one press.
Your answer
Follow this Question
Related Questions
Detection of device fall 0 Answers
Mouse and Oculus Touch Controller Inputs 0 Answers
Why is the keypress only registered on the second press? 3 Answers
what is enter for input 3 Answers
Controllong Objects with Data 0 Answers