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 darkmwar · Aug 06, 2014 at 08:36 AM · bugtouchtouchscreen

VERY weird touch responses. BUG?

Have I found a bug in unity? i wrote this script to detect swipes / tap to be calculated by the distance between the beginning of the touch and the end of the touch.If I move left or right more than 100 units, then it is a swipe, other wise its a tap.

The problem is that when I tap the screen, it understands that it is a tap, but it also think that it is a swipe.

So when I tap the screen, console:

Debug.Log message : tap

Debug.Log message : swipe

//////

Debug.Log message : tap

Debug.Log message : swipe

///////

But when I swipe, it is fine. console:

Debug.Log message : swipe

///////

Debug.Log message : swipe

///////

Here is the code:

// I put this code in a GUI function because I use some gui labels, and I don't want to put it in update() because it might cause error if it updates while it is in the middle of the touch.

//float distance = 0

                             foreach (Touch t in Input.touches) {
                                 
                                         if (t.phase == TouchPhase.Began) {
                                                 distance = t.position.x;
                                         } 
                                         if (t.phase == TouchPhase.Ended) {
                                                 distance = distance - t.position.x;
                                                 if (distance > 100 || distance < -100) {
                                                 Debug.Log ("swipe");
                                                 } else {
                                                 Debug.Log ("tap");
                                                 }
                                                 distance = 0;
                                         }                                    
                                 }
                         



any idea?

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
2
Best Answer

Answer by tanoshimi · Aug 06, 2014 at 08:40 AM

I suspect your problem comes because you've put it in OnGUI, which is called multiple times per frame - for each "tap" that ends you're therefore subtracting the position several times and always recording a distance of < -100.

Don't ever include code logic in OnGUI - only put in GUI code.

Comment
Add comment · Show 2 · 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 darkmwar · Aug 06, 2014 at 09:03 AM 0
Share

@tanoshimi thanks for your reply. I forgot about that. Where should i include those code then? If i put it in the update function, it will crash right? Because it would be the same as a while loop inside an update?

avatar image HarshadK · Aug 06, 2014 at 09:12 AM 0
Share

Let me quote the documentation:

Note also that the Input flags are not reset until "Update()", so its suggested you make all the Input Calls in the Update Loop.

Also if you think there might be some issues due to putting your code into Update then you might think of restructuring your code.

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

2 People are following this question.

avatar image avatar image

Related Questions

InputSystem simulated touchscreen stops working from v1.1.0 preview 1 0 Answers

Bug moving a character with onscreen Joystick prefab 0 Answers

smooth movement with rigidbody2D 1 Answer

Unity Getting Input from Horizontal axis while using buttons 1 Answer

Application in windowed mode - Why does finger-touch work with Unity4x and no longer with Unity5x? 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