Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Karaka · Oct 28, 2015 at 02:09 AM · inputbuttonkeycode

How to add double taping and button combination to games.

Hi. In my game I want to make button combinations for different fighting combos and double tapping buttons for things like sprinting. How can I do this and also make sure that if the buttons are not pressed within a second of each other, they will do individual moves?

Thanks for reading this,

-SK

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 GiyomuGames · Oct 28, 2015 at 02:23 AM

I guess you need to handle each button press normally (otherwise you will have lag which is not pleasant for the player). However if another button is pressed very quickly (<.25 seconds?) then you cancel what you started doing and do whatever your combo / double tap is supposed to do.

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 Karaka · Nov 07, 2015 at 07:50 PM 0
Share

Thanks for the answer but would you $$anonymous$$d elaborating on it?

avatar image GiyomuGames Karaka · Nov 09, 2015 at 12:42 AM 0
Share

Let's say you want to detect that the player has pressed the space bar twice in less than 0.1 seconds. You can have a variable bool spacePressedOnce and a variable spacePressedTime.

Then you do something like

 if (Input.Get$$anonymous$$eyDown("space"))
 {
          if (spacePressedOnce && spacePressedTime - Time.time < .1f)
          {
                      // here you do whatever you want to do when space if pressed twice in less than .1s
                      // We reset the spacePressedOnce variable
                      spacePressedOnce = false;
          }
          else
          {
                      // This is your normal case where space is pressed once so you do the normal thing
                      // Set the spacePressedOnce variable and store the time it was pressed
                      spacePressedOnce = true;
                      spacePressedTime = Time.time;
          }
  }

Now this would only work for this specific and simple case. For more complicated combos you'd need a much smarter approach, probably using a graph similar to the animator graph. I have never tried and can't really help for that sorry.

avatar image
0

Answer by arcifus · Oct 28, 2015 at 01:07 PM

I wouldn't re-invent the input handling wheel for such a game. There are some nice ready made assets on the asset store that will handle a lot of input combos for you. You can concentrate on other aspects of your game instead.

Here is one such package: https://www.assetstore.unity3d.com/en/#!/content/3283

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

34 People are following this question.

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

Related Questions

gui button to work exctly like up arrow key 1 Answer

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Is there any function to check how long a button is pressed? 2 Answers

OVRInput keys are not working 0 Answers

multiple inputs 2 Answers


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