This question is purely academic. I’m not actually making a game of this kind right now. But I’m curious about the concept.
Mechanically the question is:
How would you code a combination of sequenced button-presses as the trigger for a script or function, but with a certain (but non-infinite) amount of flexibility to the timing thereof?
For the specific example in question, the game has to accept down, then down+forward, then forward, and at some point while forward is still held or immediately after it’s released an attack button has to be pressed.
It’s a simple timer. You record the timestamp at which the first input of a sequence is entered. Then you see whether the second input is received within a certain time window. If it is, you reset the timestamp and listen for the third input and so on until the entire sequence is received. If not, you start listening for the first input again.
char[] sequence = {'u', 'd', 'l', 'r'};
int i=0;
if(i==0 || Time.time - lastInputTime < acceptableTime) {
if(input = sequence*) {*
i++;
lastInputTime = Time.time;
if(i==sequence.Length) {
// Combo performed
i=0;
}
} else {
i=0;
}