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 /
This question was closed Oct 02, 2014 at 10:17 AM by RedDevil for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by RedDevil · Oct 02, 2014 at 09:11 AM · iostouchswipe

Unity iOS Swipe not working

Hi! I have this code where if i swipe down i want to activate and deactivate some colliders and the oposite if i swipe up but it does not seem to work.Can someone tell me what is wrong with it?Thanks

 void Update()
     {
         if(Input.touchCount > 0)
         {
             Touch touch = Input.touches[0];
             switch(touch.phase)
             {
                 case TouchPhase.Began:
                 {
                     startPos = touch.position;
                     up.enabled = false;
                     down.enabled = false;
                     break;
                 }
                 case TouchPhase.Ended:
                 {
                     float swipeDistVertical = (new Vector3(0,touch.position.y,0) - new Vector3(0,startPos.y,0)).magnitude;
                     if(swipeDistVertical > minSwipeDistY)
                     {
                         float swipeValue = Mathf.Sign(touch.position.y - startPos.y);
                         if (swipeValue > 0)//up swipe
                         {
                             down.enabled = false;
                             up.enabled = true;
                         }
                         else if (swipeValue < 0)//down swipe
                         {
                             up.enabled = false;    
                             down.enabled = true;
                         }
                     }
                     break;
                 }
             }
         }
     }    

 
Comment
Add comment · Show 3
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 ahaykal · Oct 02, 2014 at 09:36 AM 0
Share

Could you show us the whole script? Try to insert print statements inside the touchpaseended and check if it is entering there or not. Up could not be referenced somewhere or there might be something wrong with the swipe script.

avatar image RedDevil · Oct 02, 2014 at 09:49 AM 0
Share

that is the whole script

avatar image RedDevil · Oct 02, 2014 at 10:09 AM 0
Share

I know for sure after testing that it reaches the float swipeDistVertical but then it does not go further

1 Reply

  • Sort: 
avatar image
0

Answer by alap soni · Oct 02, 2014 at 10:24 AM

Try using Input.getTouch(0)

instead of input.touches.

Comment
Add comment · 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 aos-ap · Jul 11, 2020 at 11:18 AM 0
Share

Check this code and see if it solves your issue.

void Update() { #if UNITY_ANDROID || UNITY_IPHONE if (Input.touchCount > 0) { Touch touch = Input.touches[0];

     switch (touch.phase)
     {
         case TouchPhase.Began:
             startPos = touch.position;
             StartCoroutine(Jump());
             break;
         case TouchPhase.$$anonymous$$oved:
             isSwipe = true;
             float swipeDistHorizontal = (new Vector3(touch.position.x, 0, 0) - new Vector3(startPos.x, 0, 0)).magnitude;
             float swipeDistVertical = (new Vector3(0, touch.position.y, 0) - new Vector3(0, startPos.y, 0)).magnitude;
             if (swipeDistHorizontal > $$anonymous$$SwipeDistX)
             {
                 float swipeValue = $$anonymous$$athf.Sign(touch.position.x - startPos.x);
                 if (swipeValue > 0 && !isTouch)//to right swipe
                 {
                     isTouch = true;
                     StartCoroutine(Right());
                 }
                 else if (swipeValue < 0 && !isTouch)//to left swipe
                 {
                     isTouch = true;
                     StartCoroutine(Left());
                 }
             }

             //add swipe to up
             if(swipeDistVertical > $$anonymous$$SwipeDistY)
             {
                 float swipeValue = $$anonymous$$athf.Sign(touch.position.y - startPos.y);
                 if(swipeValue > 0 && !isTouch)
                 {
                     isTouch = true;
                     StartCoroutine(Jump2());
                 }
             }
             break;
         case TouchPhase.Ended:
             isSwipe = false;
             isTouch = false;
             break;
     }
 }
 #endif

} IEnumerator Jump2() { yield return new WaitForSeconds(0.05f); if(playerVelocity <= 0.2f) { Debug.Log("Swipe Up"); } }

IEnumerator Jump() { if (!isSwipe) { yield return new WaitForSeconds(0.05f); if (!isSwipe && playerVelocity <= 0.2f) { Debug.Log("Tap");

     }
     else
     {
         yield break;
     }
 }
 else
 {
     yield break;
 }

}

IEnumerator Right() { Debug.Log("Right");

}

IEnumerator Left() { Debug.Log("Left");

}

AOS TV

Follow this Question

Answers Answers and Comments

29 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

Related Questions

Recommendations on best way to begin implementing Swipe for iOS game? 1 Answer

Detect swipe up gesture IOS 1 Answer

How can I swipe function that lets the player select buttons? 0 Answers

Unity2D iOS Dragable items by touch 0 Answers

Swipe Control Issue.. Need help 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