• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Dinart Filho 1 · Feb 19, 2011 at 08:05 AM · buttonkeysequencecombo

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!

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by NewfieJoe · Feb 19, 2011 at 02:27 PM

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.

Comment
Dinart Filho 1

People who like this

2 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dinart Filho 1 · Feb 19, 2011 at 07:07 PM 0
Share

do you have an exemple in js?

avatar image
Best Answer

Answer by rudolfwm · Feb 19, 2011 at 02:31 PM

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&gt;=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 :)

Comment
GesterX
Dinart Filho 1

People who like this

3 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dinart Filho 1 · Feb 19, 2011 at 07:07 PM 0
Share

Sorry, i am very noob in programming, i just know javascript.

avatar image

Answer by masfelix · Jun 15, 2011 at 05:16 PM

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?

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by $$anonymous$$ · May 01, 2012 at 04:57 PM

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

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by leodluz · Mar 04, 2018 at 09:09 PM

see Button Sequence Detector

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How to have multiple charge attacks on two buttons? 0 Answers

How to push down a button and hold it through script? 0 Answers

GetKey/GetButton not working if 2 Adjacent keys are being pressed at the same time 1 Answer

Seven key press 3 Answers

Why right alt (alt gr) acts like left ctrl?! 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges