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 androids · May 09, 2013 at 08:59 PM · swipefix

Fix Swipe problem

I'm using and if the position of the character is bigger than 80 on the x axis. It's not possible to swipe to the right. And if the position of the character is smaller than -80 on the x axis, It's not possible to swipe to the left. This is the whole script:

     var minMovement: float = 20.0f;
     var sendLeftMessage: boolean = true;
     var sendRightMessage: boolean = true;
     var MessageTarget: GameObject = null;
  
     private var StartPos : Vector2;
     private var SwipeID = -1;
  
     function Update ()
     {
         if (MessageTarget == null)
             MessageTarget = gameObject;
         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.Moved && delta.magnitude > minMovement)
                 {
                     SwipeID = -1;
                     if (Mathf.Abs(delta.x) > Mathf.Abs(delta.y))
                     {
                         if (sendRightMessage && delta.x > 0)
                             MessageTarget.SendMessage("OnSwipeRight", SendMessageOptions.DontRequireReceiver);
                         else if (sendLeftMessage && delta.x < 0)
                             MessageTarget.SendMessage("OnSwipeLeft", SendMessageOptions.DontRequireReceiver);
                     }
                 }
                 else if (T.phase == TouchPhase.Canceled || T.phase == TouchPhase.Ended)
                     SwipeID = -1;
             }
         }
     }
     
     function OnSwipeLeft()
 {
         transform.position -= Vector3.right*80;
         animation.CrossFade("LeftMove");
         if (transform.position.x > 80){
         //I don't have any idea what to do to prevent the character goes further than x=-80
         //If the x position is -80, you can't slide to the left anymore
         }
 }
     
     function OnSwipeRight()
 {
         transform.position += Vector3.right*80;
         animation.CrossFade ("RightMove");
         if (transform.position.x > 80){
         //I don't have any idea what to do to prevent the character goes further than x=80
         //If the x position is 80, you can't slide to the right anymore
         }
         
     }

But I have to do something with this part of the script:

 function OnSwipeLeft()
     {
             transform.position -= Vector3.right*80;
             animation.CrossFade("LeftMove");
             if (transform.position.x > 80){
             //I don't have any idea what to do to prevent the character goes further than x=-80
             //If the x position is -80, you can't slide to the left anymore
             }
     }
         
         function OnSwipeRight()
     {
             transform.position += Vector3.right*80;
             animation.CrossFade ("RightMove");
             if (transform.position.x > 80){
             //I don't have any idea what to do to prevent the character goes further than x=80
             //If the x position is 80, you can't slide to the right anymore
             }
             
         }

Please help someone :D

EDIT

Someone who can help me? I tried something, but it was nothing.

Comment
Add comment · Show 1
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 Owen-Reynolds · May 10, 2013 at 07:08 AM 2
Share

So, the player will always be at -80, 0 or +80? In that case, just change the SwipeLeft if to if(x>-40) (picked -40 just because it's in-between.) Likewise rightSwipe can check x<40.

1 Reply

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

Answer by Fornoreason1000 · May 09, 2013 at 10:09 PM

just make swipe do nothing, you can do this by making you swipe commands conditional or setting the sensitivity to 0

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

15 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

Related Questions

Walls move when the character moves ! 4 Answers

Unity - Avatar problem? 0 Answers

mass placed trees dont collide 1 Answer

How do i fix "There was a problem communicating with the license server. Would you like to manually activate?" 1 Answer

error CS0103: The name `FiredShot' does not exist in the current context 2 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