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 KetihG28 · May 01, 2015 at 11:55 PM · touchcontrolstouchscreenattackcommand

How to control touch commands.

Hello everyone,

I have been working on a project for quite some time now and I can not find out how to solve the issue that I'm having with touchscreen commands. I currently have a touch script that tells the tap value to increment everytime the player touches the kick button and the other conditions are met.

 //Check to see if the player is attacking and if the timer is less than equal than 0
 
 if (playerScript.IsComboAnimationPlaying == false && touchKick == true && timer <= 0) 
 {
     //If conditions are met, increment the tap value per key press
     tap++;
 
     //Keep record of the last time the attack button was pressed
     LastPress = Time.timeSinceLevelLoad;
 }



    //Check to see if the player is attacking
    if (playerScript.IsComboAnimationPlaying == false) 
     {
              //If conditions are met, start the timer
              timer -= Time.deltaTime;
 
             //Check to see if the timer value is less than equal to 0
         if (timer <= 0) 
             {
             //If conditions are met, set timer to the resetTimer value, which is 0
             timer = restTime;
         }
     }

The problem I have is conditioning the tap value to only change once the attack animation is completed. I have this ---> playerScript.IsComboAnimationPlaying used as an animation event to control the animation flow. Works fine. As of now, I can touch my kick guitexture and the tap value will increment every time I touch that texture despite my player attack is condition to work one at a time. Can anyone give me any advice to control a user's touch to only be detected once the player's animation has completed. Thanks for you time.

Note: The timer is an alternative that I do not like using because each animation has a different animation length and using timer is currently causing delays in the animation flow. It is inaccurate and do not work will with the animations I have but it does force the tap value to only change when the timer is 0.

Comment
Add comment · Show 2
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 zeppike · May 02, 2015 at 07:42 AM 0
Share

I cannot see any major flaw in this script, can you provide a sample from the playerScript. Also if you log the isComboAnimationPlaying variable in update, is it working as expected?

avatar image KetihG28 · May 02, 2015 at 11:37 PM 0
Share

Thanks for your response zeppike. The isComboAniamtionPlaying variable is working perfect in the update script. Here is a snippet of the combo script that controls the animation flow:

 void Combo () 
     {
         if(attack)
         {
             switch (tap)
             {
                 
             case 0:
                 //Reset to Idle
                 anim.Play("kyo_idle");
                 break;
                 
             case 1:
                 //Combo Start
                 anim.SetBool("kickAttack1", true);
                 IsComboAnimationPlaying = true;
                 comboTimer = 0.5333334f;
                 StartCoroutine(ShowCurrentClipLength());
                 //Cause tap to increment after this animation. $$anonymous$$ay need to use AnimationEvent
                 //Debug.Log ("Tap: " + tap);
                 break;
                 
             case 2:
                 //Combo Prolonge
                 //Debug.Log ("Now on the second kick!");
                 anim.SetBool("kickAttack2", true);
                 IsComboAnimationPlaying = true;
                 comboTimer = 0.3291925f;
                 StartCoroutine(ShowCurrentClipLength());
                 break;
                 
             case 3:
                 //Combo Finished
                 anim.SetBool("kickAttack3", true);
                 IsComboAnimationPlaying = true;
                 comboTimer = 0.3409091f;
                 StartCoroutine(ShowCurrentClipLength());
                 //Debug.Log ("tap: " + tap);
                 break;
             }
             //Every attack command, allow comboTimer to start
             //comboTimer = comboResetTimer;
 
         }
     }

Here is where I have the isComboAnimationPlaying function that turns the value to false once the animation is over:

 void AnimationIsOver()
     {
         
         IsComboAnimationPlaying = false;
         anim.SetBool("kickAttack1", false);
         anim.SetBool("kickAttack2", false);
         anim.SetBool("kickAttack3", false);
         anim.SetBool("punchAttack1", false);
         anim.SetBool("punchAttack2", false);
         //Debug.Log ("isComboAnimationPlaying: " + IsComboAnimationPlaying);
         
         //Debug.Log ("Animation has finished");
     }

All this works fine, I just would like to set my tap value, so that it works in the same way.

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Make an Object follow your touch 0 Answers

I have my touch controls configured but they don't move across the entire background 0 Answers

How do I change this 2D script to touch controls to go up and down with swipe or on screen buttons? 1 Answer

Touchscreen Combo System Issue 0 Answers

Drag a ball to add force to a ball by touch screen 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