- Home /
how to keep input for several seconds without holding the key.
I am making a car game. For boost the car I use 'input.getkey' method. When I press the key it works. But I have to hold the key to continue boosting. I want to keep that boosting for 5 seconds in single press. Please Help me.
Answer by h3iberg · Oct 30, 2020 at 08:53 PM
I'm learning C#, i'll try to answer you but it would be great if we have more insight from experienced programmers. Ah, and helps a lot if you show us your code so we have a better scenario.
I think what you really need is how to make a timer.
private float BoostTimer;
private float BoostLength = 5;
if (BoostTimer < BoostLength)
{
// insert here your boosting code
}
else if (BoostTimer > BoostLength)
{
// insert here not boosted speed code
}
BoostTimer += Time.fixedDeltaTime; // this will add time value as its counting
BoostTimer = 0; // You have to reset it somewhere
I think I can assist better if you show your code.
Your answer
![](https://koobas.hobune.stream/wayback/20220613014914im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
What key was pressed? 4 Answers
Teleportation 1 Answer
Should character direction come from key press, or third person controller vector3? 0 Answers
make an object explode 3 Answers
Is it possible to have hotkeys for characters like å, ä, ö? 3 Answers