How could i script an auto-reseting successive sequence of numbers?

Hi…

i´m looking for a way to script a sequence of punchs (a combo)… each combo has a number ID…

for instance:

If player presses punch button, then player will perform punch 1…
if player presses again the same button, then player will perform punch 2…
if player presses again the same button, then player will perform punch 3…

and so…

i have created a var called “sequenceNum” that increases each time you press punch button…:

if (Input.GetButton("punch")  sequenceNum == 0){

punch 1

sequenceNum = 1;

}



else if (Input.GetButton("punch")  sequenceNum == 1){

punch 2

sequenceNum = 2;

}



else if (Input.GetButton("punch")  sequenceNum == 2){

punch 3

sequenceNum = 3;

}

that works… but i´m looking for a way that the sequence returns to 0 if you have stopped pressing the punch button for a certain time…

For example:

I press punch button, … player performs a punch. i have 0.5 seconds to press again punch button to increase sequence number and get the next punch, else the sequence counter will return to zero …

Thank you!

Keep the time of each press.

If you detect the button is pushed, before you check what state you’re in, see if you need to reset the state.

Pseudocode:

    what's the current time?

    if button is pushed,
        if (current time - last time) > threshold,
             reset the state

        perform the task for this state
        advance the state to the next state

        record the last time pressed as the current time

hi thanks for answering…!

what do you mean with " what’s the current time?" , are you talking about the sequenceNum var, or Time.Time builtin function?

Mike