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 LightSky · Sep 19, 2012 at 03:51 PM · mobiledetectiononmouseup

Mobile equivilent of onMouseUp

I have been working with the controls for mobile devices and have the clicking working fine.
However I want to implement swipes and have a small issue of when you attempt to swipe (on the initial touch) it clicks on the initial swipe action. Since my screen is full all the time it becomes very problem-some if you click when performing a swipe. Is there a way of having mobile devices have a onMouseUp type of detection? It might be small and I am just overlooking it.

Current code for touch:

 if (Input.touchCount == 1)         {
             if (Input.GetTouch(0).phase == TouchPhase.Began)
             {
                Ray ray = Camera.main.ScreenPointToRay
 (Input.GetTouch(0).position);
                RaycastHit hit = new RaycastHit();
                if (collider && collider.Raycast (ray,out hit,
 100.0f))
                {OnMouseDown();}
                }         }

Thanks :)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by whydoidoit · Sep 19, 2012 at 03:53 PM

Yes! Use TouchPhase.Ended instead of began.

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 LightSky · Sep 19, 2012 at 05:22 PM 0
Share

Would TouchPhase.Ended work the same as On$$anonymous$$ouseUp when used with a physical mouse or does it only use the "Ended" on a touch-pad. I'm just wondering this because the TouchPhase.Ended isn't working for me and is working like it did with TouchPhase.Begin.
Only things I can see wrong with it is if it is an issue because the objects are moving while they are being clicked, TouchPhase.Ended doesn't work with physical mouses and touch-pads only or my code is somehow broken. (I only changed Began to Ended)

Thanks for the responses, i'm a bit new to Unity and trying to grasp the PC/$$anonymous$$obile differences. Your help is very appreciated.

avatar image whydoidoit · Sep 19, 2012 at 05:25 PM 0
Share

Hmmm, sometimes it can miss Ended - it depends on what input method your mobile project uses and what platform it is on. Ended should occur when you take your finger off the touch screen. You could also check for Cancelled. Would be worth putting some debug.log messages in there and testing it out in the editor with Unity Remote.

avatar image
0

Answer by Graham-Dunnett · Sep 19, 2012 at 03:56 PM

Most "mouse down" type interaction on a touch screen is "press and hold" so there is a very slight delay between you touching the screen and the action (ray cast in your case). A swipe is a touch and move. So, if after say 0.1s the touch position has moved then you are doing a swipe, and if not then you are doing a "mouse click".

The equivalent of a mouse up is TouchPhase.Ended.

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

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

Samsung Galaxy S1 Not detected. 1 Answer

Detect if running on mobile vs desktop 2 Answers

Mobile Face Detection 1 Answer

How do I detect the supported OpenGL versions of a device. 1 Answer

Mobile device location and rotation detection 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