- Home /
Android OnTouch Event
Hi,
What is the correct way to detect touch inputs for android devices? As far as I know there does not exist a OnTouch method. I could use OnMouseDown since this method is also triggered during a touch event, but is this a good thing to do (e.g. does it work on every device?) The only other idea I had was to constantly check for Touches during the Update method, but that seems not very efficient.
Greets
Answer by Ali-hatem · Apr 17, 2016 at 10:06 AM
i think OnMouseDown
will cheek every frame if there is a mouse input it's like update so you have to cheek touch in update & with touch you will have more control like TouchPhase to detect if the touch begin or lifted or moved etc... so all you need to cheek for touch is if (Input.touchCount > 0)
& inside this you can cheek for touch Phase
void Update() {
if (Input.touchCount > 0){
print("ther is a touch");
if(Input.GetTouch(0).phase == TouchPhase.Began){
print("Touch has Began");
}
if(Input.GetTouch(0).phase == TouchPhase.Ended){
print("Touch has Ended");
}
}
}
Your answer
Follow this Question
Related Questions
Unresponsive to touch events in android. RaycastHit2D not working anymore? 0 Answers
How do I intercept touch events in Android native code? 0 Answers
any one now about the touch events of android swipe events on the android 1 Answer
How do you map touch points to world space? 1 Answer
If you help me, i make you 3d object 1 Answer