Question by
muller100 · Mar 02, 2016 at 06:41 PM ·
jumpingtouch controlstouchscreenhealth
Touch control swipe up to jump
This is probably extremely simple but bare with me i'm new to touch inputs. I'm creating a game for android devices where when the player swipes up the character jumps. Any insight on how to achieve this?
Comment
Answer by victor-soares655 · Apr 08, 2016 at 07:51 PM
A simple script snippet for this would be:
void checkTouch(){
for (int i = 0; i < Input.touchCount; i++) {
Touch touch = Input.GetTouch (i);
if (touch.phase == TouchPhase.Began) {
startTouchPosition = touch.position.y;
} else if (touch.phase == TouchPhase.Ended) {
endTouchPosition = touch.position.y;
if (endTouchPosition > startTouchPosition) {
jump ();
}
}
}
}
Now you'd have to implement the "jump()" method to make your character jump.