Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by puzzledragon · Dec 09, 2011 at 09:54 PM · javascriptinputbuttoncombo

multiple inputs

Hello I'd like to be able to receive multiple inputs for things like animations, AI scripts, etc. For example pressing multiple buttons at once or a sequence of buttons in a correct order I don't understand how I would phrase this in code (be aware I am not familiar with C# or Boo so Javacript related advice only) thank you in advance.

-PuzzleDragon

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Justin Warner · Dec 10, 2011 at 02:59 AM

Let's say you need the user to push the key:

a b b a

and you do a backflip.

So, you monitor the keys pushed on the update function. You could simply have a string where you do a contains "abba" and if true, then it does so said action, restarts the string, and then you continue.

This is how I'd go about it, but then your string could get pretty long if the user isn't really doing anything but button mashing the key buttons without any combos...

Check out the Input in the API: http://unity3d.com/support/documentation/ScriptReference/Input.html

Comment
Add comment · Show 2 · 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 syclamoth · Dec 10, 2011 at 04:56 AM 0
Share

You could use some kind of 'first-in-first-out' system with the keypresses, and only store the most recent four or so.

avatar image Justin Warner · Dec 10, 2011 at 03:00 PM 0
Share

A queue is a first in first out I thought? Lol. But yes, the storing of only the most recent for what you need is smart... Didn't even think of that. Lol.

avatar image
0

Answer by gfr · Dec 10, 2011 at 09:43 AM

Detecting multiple buttons pressed simultanously is fairly straight-forward, e.g. in the simplest case you could just check `Input.GetKey()` for all keys in that combo.

Processing real combos gets a bit more involved. I'd probably start with an approach like this:

  • track the buttons pressed with a e.g. queue or array, limited to N entries as you don't want to track 100s of keypresses

  • for either each or the last key pressed track when it occured so you can e.g. dismiss combos when there are 60 second pauses between presses

  • on new keypresses check against a list of valid combos (i.e. lists of keys) to map them to specific actions

  • reset the list of tracked keypresses on certain occasions (activated combos, other in-game influences like a character taking a hit, above-mentioned timeouts, ...)

  • possibly apply more complicated checks for the timings, e.g. you might require some keypresses to occur near the end of a characters action/animation

    [2]: http://en.wikipedia.org/wiki/FIFO

Comment
Add comment · 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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get the key from the button name 1 Answer

How can I make a gui with buttons pop up in javasript? 1 Answer

How do you only Instantiate only once when pressing a button once? 2 Answers

Scripting a Konami Code 1 Answer

How do you call from another script? 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