- Home /
Key Press resetting when leaving a trigger.
Hey,
So I'm working on a game where the player can enter and exit triggers and pressing spacebar while in the triggers runs a function. I need it to be on Input.GetKey instead of GetKeyDown because it ticks over something for the duration of holding spacebar down.
The problem I'm having is a player can press down in one trigger, keep the button pressed and walk over to another trigger and it'll carry on. I need a way of resetting the button press when the player leaves the first trigger so that they have to repress to start in the next trigger.
Is there a function that resets the press, even if the button is still being held down? So the game think the button has been released and then requires the press again?
To be clear, I know how to call on leaving a trigger etc, I just need the method for resetting the button press without actually letting go.
Thanks in advance! :)
Answer by zactanpeterson · Apr 22, 2020 at 06:59 PM
You can't tell the computer you have released the button unless you release the button. To solve this problem, you will probably have to have a flag, It's hard to say where and how to implement this without seeing you're code.
Thanks for this. I didn't know if there was an override to manually set it so you'd have to press again to register the press. But luckily, I've found a workaround.
For anyone else who might have a similar issue, I had several things turning off if you stopped pressing the button, but because I wasn't unpressing the button I went from one trigger to another and it still had them set to true. I made it so they could be turned off or set to null EITHER on the button no longer being pressed OR if the player left one trigger and then had a null check before running what they were needed for. Pretty simple stuff and should've spotted it earlier. Thanks anyway!