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 rupeshpamaihgari · Aug 02, 2013 at 02:36 PM · androidinput.touchgestures

Swipe functions for android.?

Hello, I am new to unity.I need java script for applying LeftSwipe,RightSwipe,UpSwipe for android.I want my character to rotate 90 degrees right on swiping right,similarly 90 degrees left on swiping left and to jump on swiping up.Can anybody please help me.I am trying to find this since one day...Thanks in advance.

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

3 Replies

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

Answer by Andre Barbosa · Aug 05, 2013 at 05:34 PM

Swipe, along with other touch based input, is easy to do, but hard to do right.

If you are in hurry, getting a plugin is probably the best advice I can give.

I have used Finger Gestures and it is great:

http://u3d.as/content/william-ravaine/finger-gestures/21Z

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 rupeshpamaihgari · Aug 05, 2013 at 06:34 PM 0
Share

is there any free plugins,as i cant afford paid one in unity assets.?..I just want script for swiping..!

avatar image
0

Answer by lancer · Aug 05, 2013 at 05:39 PM

Open up the scripting reference and look up "Input" All the swipes are handled in there.

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
avatar image
0

Answer by RickHurd · Jan 24, 2014 at 03:20 AM

Here is a reference script I found, hope it helps :D

 /* this variable is used to make use of the swipe. Once a swipe is detected
  * a function called Swipe(swipeType : Vector2) is called
  */
 
 var controller : PlayerController;
 
 // variables:
 
 private var fingerStartTime : float   = 0.0;
 private var fingerStartPos  : Vector2 = Vector2.zero;
  
 private var isSwipe         : boolean = false;
 private var minSwipeDist    : float   = 50.0;
 private var maxSwipeTime    : float   = 0.5;
  
 // main function:
 function Update()
 {
     if (Input.touchCount > 0)
     {
         for (touch : Touch in Input.touches)
         {
             switch (touch.phase)
             {
                 case TouchPhase.Began :
                     /* this is a new touch */
                     isSwipe = true;
                     fingerStartTime = Time.time;
                     fingerStartPos = touch.position;
                     break;
 
                 case TouchPhase.Canceled :
                     /* The touch is being canceled */
                     isSwipe = false;
                     break;
 
                 case TouchPhase.Ended :
                     var gestureTime : float = Time.time - fingerStartTime;
                     var gestureDist : float = (touch.position - fingerStartPos).magnitude
                     
                     if (isSwipe && gestureTime < maxSwipeTime && gestureDist > minSwipeDist)
                     {
                         var direction : Vector2 = touch.position - fingerStartPos;
                         var swipeType : Vector2 = Vector2.zero;
                         
                         if (Mathf.Abs(direction.x) > Mathf.Abs(direction.y)
                         {
                             // the swipe is horizontal:
                             swipeType = Vector2.right * Mathf.Sign(direction.x);
                         }
                         else
                         {
                             // the swipe is vertical:
                             swipeType = Vector2.up * Mathf.Sign(direction.y);
                         }
                         
                         controller.Swipe(swipeType);
                     }
 
                     break;
                 }
             }
         }
     }
 }
 
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

14 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

Related Questions

Android Gestures/Swipe Captures 1 Answer

Input.GetTouch never getting TouchPhase.Ended on Android 0 Answers

Object position resets to Camera Position using touch 1 Answer

Swipe control for circle (Can do swipe left/right) 2 Answers

using OnMouseDown instead of touch functions for touch devices 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