How to add a force to a object when a key is pressed but for a limited time?

I am trying to make a basketball game and I am trying to get it to where if you push a button it adds a force(witch I already got)

	if (Input.GetKey(KeyCode.H))
		rb.AddForce(-10, 30, 0);

But now I don’t want players to be able to just hold the key down and let the ball go flying!I also don’t want the to just keep tapping the key and make the ball keep going.Any help would be appreciated! :smiley:

You can try using a counter. Maybe something like:

private int counter = 0;
...
void Update()
{
    if (Input.GetKey(KeyCode.H))
    {
        if (counter < 10)
        {
            rb.AddForce(-10, 30, 0);
            counter++;
        }
    }
    ...
    //  Remember to reset the counter to zero when the action is finished
    //  for example when the ball returns to a player or something
}