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 Borzi · Jan 11, 2014 at 02:20 PM · buttonaxisverticalhorizontaldouble-tap

Double Clicking Horizontal/Vertical Axis

Hey! I have been trying to make a dodgeing system using double taps on the arrow keys. I tried the script here: http://answers.unity3d.com/questions/340593/how-do-i-make-a-double-tap-system-for-dashing.html but for some reason the debug is also called by simply holding the buttons down. Anybody know what im doing wrong?

 void Update () 
     {
     if(Input.GetAxis("Horizontal") > 0 || Input.GetAxis("Vertical") > 0 && IngameGUI.Instance.isInMenu == false)
         {
            if(ButtonCooler > 0 && ButtonCount == 1/*Number of Taps you want Minus One*/)
             {
             Debug.Log("Double Taped");
              //Has double tapped
               }
             else
             {
             ButtonCooler = 0.5f; 
             ButtonCount += 1 ;
              }
    }
    if(ButtonCooler > 0)
    {
  
       ButtonCooler -= 1 * Time.deltaTime ;
  
    }else
     {
       ButtonCount = 0 ;
       }
 }
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

1 Reply

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

Answer by ICHeeryI · Jan 11, 2014 at 02:26 PM

Im not sure, but I think that you want something like this.. http://docs.unity3d.com/Documentation/ScriptReference/Input.GetKey.html

     var keyA : int = 0;
     if(Input.GetKeyDown(Keycode.A)){ //We pressed key A
     if(keyA ==0)keyA = 1; //If keyA is 0 then set it to one
     else(keyA == 1)keyA =2; //If keyA is 1 then set it to two
     }
     else if(keyA==2){
     //Double tapped so we reset
     keyA =0;
     }
     else{
     //This mean there is only 1 key pressed or no key is pressed
     //You need to add time here, after 1 sec keyA will be again 0
     }


Axis code(Double tap)(JS):

 var hzH : int = 0;//Axis
 var hzSwitch : boolean = false; //Switch
 var pressedTime : float; //Time
 
 function Update () 
     {
     //If pressed twice
     if(hzH==2){
     Debug.Log("HE PRESSED IT TWICE :O"); //Random text ;)
     pressedTime = 0; //Return time value
     hzH=0; //Return press value
     }
     if(hzH==1){ //If we pressed once count down seconds
         pressedTime += Time.deltaTime;
     }
     //We pressed anything?
     if(Input.GetAxis("Horizontal") || Input.GetAxis("Vertical"))
        {       
            if(Input.GetAxis("Horizontal") >0 && hzH<2){
                    hzSwitch = true; //We preseed horinzontal
            }
           }
         else if (hzSwitch && pressedTime<=2){ //Time is not up? We must press again that axis to turn on hzSwitch
                if(hzH==0){hzH=1;hzSwitch = false;}
                else if(hzH==1){hzH=2;hzSwitch = false;}
       }
        if(hzH==1 && pressedTime>=2){ //We only pressed it once and time is up
         pressedTime=0;
         hzH=0;
       }
 }
Comment
Add comment · Show 6 · 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 Borzi · Jan 12, 2014 at 12:05 AM 0
Share

Thanks for your reply! So how would this work for the axis? Because as far as I know they are not a key (I might be wrong)

avatar image ICHeeryI · Jan 12, 2014 at 08:59 AM 0
Share

Best method is to use something that tell you what button is pressed, axis doesn't have that. But anyway I assume that you love using axis ;). I updated my answer with a new code. As you can see there is so much going on. That's why is better to use getkeydown. Anyway, GoodLuck!

avatar image Borzi · Jan 12, 2014 at 10:19 AM 0
Share

Ahhh I already like you :D Okay I will check it out thank you very much! I'll leave a tick if it works

avatar image Borzi · Jan 12, 2014 at 04:45 PM 0
Share

Okay so unfortunately, it turns out that the script does not work. I have added all kinds of debugs and it turns out that the line for when it is pressed twice does get called occasionally, but not due to a double tap (in fact, I don't even know how its called). Anyway, here is the code I have with debugs, maybe I did something wrong :P

 if(hzH == 2)
         {
         Debug.Log("HE PRESSED IT TWICE :O"); //Random text ;)
             pressedTime = 0; //Return time value
            hzH = 0; //Return press value
            }
     if(hzH == 1)
         { //If we pressed once count down seconds
         pressedTime += Time.deltaTime;    
         }
     //We pressed anything?
     if(Input.GetAxis("Horizontal") > 0 || Input.GetAxis("Vertical") > 0)
        {       
            if(Input.GetAxis("Horizontal") > 0 && hzH < 2)
                 {
                 hzSwitch = true; //We preseed horinzontal
                    }
         else if (hzSwitch && pressedTime <= 2)
         { //Time is not up? We must press again that axis to turn on hzSwitch
             if(hzH == 0)
             {
                 hzH = 1;
                 hzSwitch = false;
             }
             else if(hzH == 1)
             {
                 hzH = 2;
                 hzSwitch = false;
             }
        }
        }
        if(hzH == 1 && pressedTime >= 2)
         { //We only pressed it once and time is up
        pressedTime=0;
        hzH=0;
        }
avatar image ICHeeryI · Jan 12, 2014 at 08:24 PM 1
Share

Check twice :P. Remove bracket at line 30, and add it after line 17.

Show more comments

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

19 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

Related Questions

How can I make GUI button send an input message when I press it? 0 Answers

How to detect Double Clicking Horizontal/Vertical Axis on joystick 0 Answers

Touch screen horizontal or vertical swipe 6 Answers

Restricting movement on the vertical axis 1 Answer

'GetAxis' is not a member of 'function(): void' 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