Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 animeman0 · Jul 08, 2015 at 05:04 PM · c#androidinputmobileprogramming

How to check whether you have swiped upwards on a mobile device - c#

I've nearly finished the live training on mobile development. I don't think he covered this but how would you check whether someone has swiped up in the game?

I have no clue where to start!

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 Pflobus · Jul 08, 2015 at 05:16 PM 0
Share

In the live training, I don't believe you swipe up, but rather you tap. He explains it in the tutorial. And using get button down, the longer you tap, the higher the character goes. For sliding, maybe you could make an invisible slider that resets everytime you release it, and you have to make the slider go higher for a higher jump??? Otherwise, you just tap.

avatar image Owen-Reynolds · Jul 08, 2015 at 07:44 PM 0
Share

$$anonymous$$aybe Dapheono's answer is all you need. But, in general, try to think of a similar problem other people must have. In this case, Search for how to check for a swipe (in any direction.) For sure there's sideways swipe examples you can change to go up/down.

It also depends on what else can happen. If all you can do is swipe, that's one thing. If you have a tappable button, and want to be able to have a small jiggle count as a tap, and only a big move be a swipe, thats different.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Daphoeno · Jul 08, 2015 at 06:44 PM

When using the following script, play around with the minimum swipe distances for the best results (may vary on some mobile devices)... For me I found that 128 worked best for minSwipeDistY and 256 worked best for minSwipeDistX

 using UnityEngine;
 using System.Collections;
 
 public class SwipeDetector : MonoBehaviour 
 {
     
     public float minSwipeDistY;
     public float minSwipeDistX;
     
     private Vector2 startPos;
 
     public GUIStyle _responseStyle;
     public string _swipe;
     
     void Update()
     {
 
 #if UNITY_ANDROID
         if (Input.touchCount > 0){
             Touch touch = Input.touches[0];
             
             switch (touch.phase){
                 
             case TouchPhase.Began:
                 
                 startPos = touch.position;
                 
                 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
                         _swipe = "Up";
                         
                     } else if (swipeValue < 0){ //down swipe
                         _swipe = "Down";
                     }
                 }
                 
                 float swipeDistHorizontal = (new Vector3(touch.position.x,0, 0) - new Vector3(startPos.x, 0, 0)).magnitude;
                 
                 if (swipeDistHorizontal > minSwipeDistX) 
                 {
                     
                     float swipeValue = Mathf.Sign(touch.position.x - startPos.x);
                     
                     if (swipeValue > 0){ //right swipe
                         _swipe = "Right";
                     } else if (swipeValue < 0){ //left swipe
                         _swipe = "Left";
                     }
                 }
 
                 break;
             }
         }
     }
 #endif

     void OnGUI ()
     {
         GUI.Label (new Rect(10, Screen.height - 50, 100, 20), gameObject.name + ".SwipeDetector._swipe = " + _swipe, _responseStyle);
     }
 }
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

24 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

Related Questions

Multiple Cars not working 1 Answer

TouchInput doesn't not exist in current content 0 Answers

Android app is laggy 1 Answer

Detect Gyroscope's rotation around a single axis? Like a car game. 0 Answers

How can I know when the user slide his finger? 0 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