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 swifter14 · Jul 09, 2017 at 06:11 PM · touchmousepositionmultitouchgetmousebuttondown

Destroy GetMouseButtonDown event and position or force mousebuttonup

When I run my app on Android, the first finger touch calls Input.GetMouseButtonDown(0) and the second touch calls Input.GetMouseButtonDown(1). I want to override GetMouseButtonDown(0) in some cases- so the second finger (1) touch will become the first (0) and I don't know how to do it. Either this or how to force mouseButtonUp on the first finger touch- I want to remove this first "click" from the system so it'll not use Input.mousePosition in a case of 2 touches.

Why? I'm creating a paint app when the user can draw lines. There is an area when the user can paint (in a rectangle) and an area where he shouldn't, I know how to detect when pressed on an unwanted area. But sometimes the palm of my hand creates unwanted first touch Input.GetMouseButtonDown(0) on the unwanted area (without Input.GetMouseButtonUp(0)) and when I start to draw a line Input.mousePosition gets the average of both touches, so I just want a way to remove a "down" touch/click from the system. Or another way to solve my problem.

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 Jwizard93 · Jul 09, 2017 at 11:29 PM 0
Share

Paragraph is hard to follow. If no one can help you consider posting the whole script.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Jul 10, 2017 at 03:04 AM

Simply don't use GetMouseButton Up / Down or Input.mousePosition at all. Those are ment for "mouse input" on desktop systems. Unity just emulates those events based on touch events so it's easier to reuse certain methods / classes on mobile devices. This emulation does only support a single touch.

You should exclusively use the touch input (Input.touches or touchCount + GetTouch). Each touch has a fingerId which identifies that touch from the beginning to the end. You should not rely on any particular order of the touches in that "Input.touches" array. Always use the fingerId for reference.

The usual approach is to store the fingerId in a variable when the touch.phase is "Began" and on all other event types you would always check against the fingerId.

Some pseudo code:

 private int drawingFinger = -1;
 
 foreach(var t in Input.touches)
 {
     if (t.phase == TouchPhase.Began)
     {
         if (t.position is inside drawing area)
         {
             drawingFinger = t.fingerId;
             // handle additional "down" event things
         }
     }
     else if(t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled)
     {
         if (t.fingerId == drawingFinger)
         {
             drawingFinger = -1;
             // do your "up" event things
         }
     }
 }

Note: don't rely on certain hardcoded ID numbers. Only use them "relatively". So you get the ID in Began, store it while the touch is still there and mark it as invalid (-1) when the touch ended. Usually fingerIDs are allocated in sequence but as i said you shouldn't rely on it. Due to some bugs old fingerIDs might "get stuck" (happend mainly when you exit the app while still 2 or more touches where active).

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

89 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

Related Questions

Problem with multi-touch from android 1 Answer

Multitouch with two Different Scripts 0 Answers

Two or more touchs at same time? 0 Answers

Unity Bug, Letting User To touch two UI Buttons as same time (simultaneously) 1 Answer

Touch dont work 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