Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 azhan16 · Sep 12, 2017 at 11:36 AM · androidunity 5iosiphonexcode

Swipe controls work on Android but not on iOS?

Hi Everyone,

So I got a program which move a player to three places and the user can change places by swiping left or right. The issue is that it works on Android phones but on iOS phones? Why is this?

Here is the code:

//---------------------Touch Inputs------------------------- private void touch_controls() { tap = swipe_left = swipe_right = false;

     //---------------mouse inputs-------------------
     if (Input.GetMouseButtonDown(0))
     {
         tap = true;
         is_dragging = true;
         start_touch = Input.mousePosition;
     }
     else if (Input.GetMouseButtonUp(0))
     {
         is_dragging = false;
         reset_movements();
     }


     //-------------mobile inputs--------------
     //get touch information
     if (Input.touches.Length > 0)
     {
         if(Input.touches[0].phase == TouchPhase.Began)
         {
             tap = true;
             is_dragging = true;
             start_touch = Input.touches[0].position;
         }
         else if(Input.touches[0].phase == TouchPhase.Ended || Input.touches[0].phase == TouchPhase.Canceled)
         {
             is_dragging = false;
             reset_movements();
         }
     }

     //Calculate the distance
     swipe_delta = Vector2.zero;
     if(is_dragging)
     {
         if(Input.touches.Length > 0)
         {
             swipe_delta = Input.touches[0].position - start_touch;
         }
         else if (Input.GetMouseButton(0))
         {
             swipe_delta = (Vector2)Input.mousePosition - start_touch;
         }
     }

     //the length of how long the swipe must be for player movement
     float swipe_length = 75;

     if(swipe_delta.magnitude > swipe_length)
     {
         //get direction
         float x = swipe_delta.x;
         float y = swipe_delta.y;

         //horizontal swipes
         if(Mathf.Abs(x) > Mathf.Abs(y))
         {
             // left or right swipe
             if(x < 0)
             {
                 //swipe left
                 swipe_left = true;
             }
             else
             {
                 //swipe right
                 swipe_right = true;
             }
         }

         //reset values
         reset_movements();
     }
 }

 private void reset_movements()
 {
     //reset position after swipe
     start_touch = swipe_delta = Vector2.zero;
     is_dragging = false;
 }

 public Vector2 get_swipe_delta()
 {
     return swipe_delta;
 }

 public bool get_swipe_left()
 {
     return swipe_left;
 }

 public bool get_swipe_right()
 {
     return swipe_right;
 }

 private void touch_movements()
 {
     //position for player
     float left_side = -game_controller.get_camera_width() / 2 + 1;
     float middle = 0;
     float right_side = game_controller.get_camera_width() / 2 - 1;

     //speed for movement
     float player_speed = 8f;

     //swipe left function
     if (get_swipe_left())
     {
         if (player.transform.position.x == right_side)
         {
             target_position = new Vector3(middle, player.transform.position.y, player.transform.position.z);
         }
         else if (player.transform.position.x == middle)
         {
             target_position = new Vector3(left_side, player.transform.position.y, player.transform.position.z);
         }
     }

     //swipe right function
     if (get_swipe_right())
     {
         if (player.transform.position.x == left_side)
         {
             target_position = new Vector3(middle, player.transform.position.y, player.transform.position.z);
         }
         else if (player.transform.position.x == middle)
         {
             target_position = new Vector3(right_side, player.transform.position.y, player.transform.position.z);
         }
     }

     player.transform.position = Vector3.MoveTowards(player.transform.position, target_position, player_speed * Time.deltaTime);
 }


Kind regards

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 MacDx · Sep 11, 2017 at 08:59 PM 0
Share

We can make a guess but there's no way to know exactly without taking a look at the code.

avatar image azhan16 · Sep 11, 2017 at 09:12 PM 0
Share

I've added the code now...

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

226 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 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 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 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 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 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 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 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

App will not appear on my iPhone! Help! 0 Answers

Accessing the volume buttons on iPhone for some functionality through Unity 1 Answer

Simultaneous Android and iOS development 1 Answer

How does updating a game work? 0 Answers

Device Auto-Rotation 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