Help With game I am Making

Hello,

In the game I am making I want speed to increase if the key is pressed faster/spammed but if the key is pressed less (Every 5 seconds for example) Then I want the speed to be slower. Any help is very much appreciated.

Thanks.

Create a timer system that counts up when the key is pressed and then when the key is pressed again, it calculates the amount of time passed and you can pass that into a switch statement or a math statement to calculate the speed increase. Apply that speed increase, then reset the timer and start it again.

Hello!
This is the first time for me trying to give an answer so … I am afraid to give a bad advice!

I’d use something like this

public float speed = 20f;
    public float time;

    void Update()
    {
        time += Time.deltaTime;
        if (time >= 5f) { speed -= 1f * Time.deltaTime; }
        if (Input.GetKeyDown("up")) { speed += 0.25f; time = 0f; }
        Debug.Log("Time: " + time);
        Debug.Log("Speed: " + speed);
    }

So. You set initial speed (= 20f) and then you start the timer …

When 5 seconds are passed, speed will decrease by 1f. When you press UP key speed will increase and you must wait again 5 seconds to let speed decrease again.

1 Like

Thanks so much, I have been trying to get this working for ages.

1 Like

Its crazy how nice and helpful people are in this community

1 Like