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 Bananaman · Feb 17, 2013 at 04:08 AM · androidmenulevelselectionswipe

simple android swipe controls for level selection?

So I am having serious troubles getting any form of swiping to be detected. All I want to do is transform an objects x value +-1. This is for a menu that would look like most polular mobile level selection menus. Is there an easy way to do this? If so, where should I start? I have already tried the quick swipe script and can't get it to work.

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
0

Answer by GamingNewBie · Feb 17, 2013 at 07:19 AM

Drag an empty Game object to the scene attach the following script to it. I hope this will help.

using UnityEngine; using System.Collections;

public class SwipeTest : MonoBehaviour {

 Vector2 StartPos;
 int SwipeID = -1;
 float minMovement = 20.0f;
 // Use this for initialization
 void Start ()
 {
     
 }
 // Update is called once per frame
 void Update ()
 {
     foreach (var T in Input.touches) {
         var P = T.position;
         if (T.phase == TouchPhase.Began && SwipeID == -1) {
             SwipeID = T.fingerId;
             StartPos = P;
         } else if (T.fingerId == SwipeID) {
             var delta = P - StartPos;
             if (T.phase == TouchPhase.Moved && delta.magnitude > minMovement) {
                 SwipeID = -1;
                 if (Mathf.Abs (delta.x) > Mathf.Abs (delta.y)) {
                     if (delta.x > 0) {
                         
                         Debug.Log ("Swipe Right Found");
                     } else {
                         
                         Debug.Log ("Swipe Left Found");
                     }
                 } 
                 else {
                     if (delta.y > 0) {
                         
                         Debug.Log ("Swipe Up Found");
                     } else {
                         
                         Debug.Log ("Swipe Down Found");
                     }
                 }
             } else if (T.phase == TouchPhase.Canceled || T.phase == TouchPhase.Ended)
                 SwipeID = -1;
         } 
     }
 }   
 
 

}

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 Bananaman · Feb 17, 2013 at 07:33 PM 0
Share

Thanks! It's working! Do you think you could help me convert this into javascript? I tried but it didn't work. $$anonymous$$y whole project is in javascript and I need to reference things from this script and that just complicates things. Here's my failed attempt.

 var SwipeID : int = -1;
 var $$anonymous$$$$anonymous$$ovement : float = 20.0f;
 public var gridline : GameObject;
 var temp : Vector3;
 var swiping : boolean = false;
 var whichdot : int = 1;
 var dot1 : GameObject;
 var dot2 : GameObject;
 var dot3 : GameObject;
 var dot4 : GameObject;
 
 
 
 function Update ()
 
 {
 
     (whichdot == 1)
         {
             dot1.GetComponent(GUITexture).enabled = true;    
             dot2.GetComponent(GUITexture).enabled = false;
             dot3.GetComponent(GUITexture).enabled = false;
             dot4.GetComponent(GUITexture).enabled = false;
         }
         
     if(whichdot == 2)
         {
             dot2.GetComponent(GUITexture).enabled = true;    
             dot1.GetComponent(GUITexture).enabled = false;
             dot3.GetComponent(GUITexture).enabled = false;
             dot4.GetComponent(GUITexture).enabled = false;
         }
         
     if(whichdot == 3)
         {
             dot3.GetComponent(GUITexture).enabled = true;    
             dot2.GetComponent(GUITexture).enabled = false;
             dot1.GetComponent(GUITexture).enabled = false;
             dot4.GetComponent(GUITexture).enabled = false;
         }
         
     if(whichdot == 4)
         {
             dot4.GetComponent(GUITexture).enabled = true;    
             dot2.GetComponent(GUITexture).enabled = false;
             dot3.GetComponent(GUITexture).enabled = false;
             dot1.GetComponent(GUITexture).enabled = false;
         }
         
 
     temp = gridline.transform.position;    
         
     for (var T in Input.touches) {
        var P = T.position;
        if (T.phase == TouchPhase.Began && SwipeID == -1) {
          SwipeID = T.fingerId;
          StartPos = P;
        } else if (T.fingerId == SwipeID) {
          var delta = P - StartPos;
          if (T.phase == TouchPhase.$$anonymous$$oved && delta.magnitude > $$anonymous$$$$anonymous$$ovement) {
           SwipeID = -1;
           if ($$anonymous$$athf.Abs (delta.x) > $$anonymous$$athf.Abs (delta.y)) {
               if (delta.x > 0) {
                  
                  //swipe right
                 if(temp.x <= 60.28 && temp.x >= 56.28)
                     {
                         swiping = true;
                          temp.x = temp.x + 1;
                          gridline.transform.position = temp;
                         whichdot = whichdot -1;        
                         waitalittle();
                     }
               } else {
                  //swipe left
                 if(temp.x <= 60.28 && temp.x >= 56.28)
                     {
                         swiping = true;
                          temp.x = temp.x - 1;
                          gridline.transform.position = temp;    
                         whichdot = whichdot +1;        
                         waitalittle();
                     }
               }
           } 
           else {
               if (delta.y > 0) {
  
                  Debug.Log ("Swipe Up Found");
               } else {
  
                  Debug.Log ("Swipe Down Found");
               }
           }
          } else if (T.phase == TouchPhase.Canceled || T.phase == TouchPhase.Ended)
           SwipeID = -1;
        } 
     }
 }   
     
     
 function waitalittle()
     {
         yield WaitForSeconds (1);
         swiping = false;
         
     }
 
 }
 

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

12 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

Related Questions

Android Button Text 1 Answer

Changing level on Android 3 Answers

Sliding Finger(touch) gesture? 1 Answer

Language menu problem 1 Answer

pause menu on android phone 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