Best way to handle keypresses with a gamemanager

So far i’ve been using a flag system that allows me to do something with my character whenever some key is up. The problem though is that i need something to handle small impulses AND long presses (like holding to shield)

By setting something to true it does work, but i also need to set it back to false. I’ve been doing this by setting the variable to false whenever the action is done. But sometimes the game is doing something else the action never really happens so the variable stays true.

for example:

if(Input.GetKeyUp("i")){
	playerAttack = true;
}

i then set it back to false when a certain character attacks

but if then i read playerAttack do make a character attack but for some other reason she doesn’t the variable stays true. whats the best way to solve this?

hi dont ever use string for key up it works some times

the best method is

if(Input.GetKeyUp(KeyCode.I)){
 playerAttack = true;
}

and the reason the playerAttack is always true because if(Input.GetKeyUp(KeyCode.I)) is called when you are not pressing Button I

so you might have to change it to

if(Input.GetKeyDown(KeyCode.I)){
     playerAttack = true;
    }

now it checks only when you press button I
and what should happen when you press I do you want it to attack or hold the shield

Leave a comment so that i can post the script