- Home /
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 :)
Answer by whydoidoit · Sep 19, 2012 at 03:53 PM
Yes! Use TouchPhase.Ended instead of began.
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.
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.
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613081232im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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