button sequence command, how to??

Hello there, I just wanna know if is there an easy way to use a key sequence on unity. Ex

left + left = run

left + left + down + up + fire = fatality1

things like that.

thanks in advance!

Use the following class:

public class KeySequence
{
    public delegate void HandleCallback(KeySequence pSequence);
    List<string> mKeyList = new List<string>();
    int mProgressIndex = 0 ;
    HandleCallback mHCB = null;

    public KeySequence(HandleCallback pCallbackFunction)
    {
        mHCB = pCallbackFunction;
    }
    public void AddKey2Sequence(string pKeyStr)
    {
        mKeyList.Add(pKeyStr);
    }
    public void  Update()
    {
        if(mKeyList.Count==0)
        {
            return ;
        }
        if(Input.GetKey(mKeyList[mProgressIndex]))
        {
            mProgressIndex++;
            if(mProgressIndex>=mKeyList.Count)
            {
                if(mHCB!=null)
                {
                    mProgressIndex=0;
                    mHCB(this);
                }
            }
        }
        else
        {
            mProgressIndex=0;
        }
    }
}

Now you can make a keysequence like this:

KeySequence lTestSequence = new KeySequence(new KeySequence.HandleCallback(TestSequencePressed));
lTestSequence.AddKey2Sequence("left");
lTestSequence.AddKey2Sequence("right");
lTestSequence.AddKey2Sequence("left");

Then you put lTestSequence.Update() in your update routine.

Now when the sequence is correctly entere the function TestSequencePressed will be called with the sequence object that fired. You will have to declare this function somewhere of course :)

You could use a string as an input buffer with each input adding a command to the end and removing one from the beginning then you only have to do checks based on the last command in the sequence. So if it's checking "fire" it can parse the string at the beginning of the "fire" function and see if the previous inputs were "left-left-down-up-fire", if so branch off to the alternate function for the fatality.

I put de code:

KeySequence lTestSequence = new KeySequence(new KeySequence.HandleCallback(TestSequencePressed));
lTestSequence.AddKey2Sequence(“left”);
lTestSequence.AddKey2Sequence(“right”);
lTestSequence.AddKey2Sequence(“left”);

in FixedUpdate, but i receive a erro in delegate.

A create a function named TestSequencePressed,I put
KeySequence lTestSequence = new KeySequence(new KeySequence.HandleCallback(TestSequencePressed));
lTestSequence.AddKey2Sequence(“left”);
lTestSequence.AddKey2Sequence(“right”);
lTestSequence.AddKey2Sequence(“left”);

In Function FixedUpdate(), but she has a error in delegate, Why?

Here : unitynoobs you can download a small project with this answer!

see Button Sequence Detector