Hello
Recently I’ve been developing a game in which your character jumps whn you swipe up and hides when you swipe down. My code is this:
for (var i = 0; i < Input.touchCount; ++i) {
if(Input.touchCount > 0){
if (Input.touchCount - 1 == i) {
var t : Touch = Input.GetTouch(i);
if (t.phase == TouchPhase.Began)
{
touchBegin = new Vector2(t.position.x, t.position.y);
}
if (t.phase == TouchPhase.Moved){
touchEnd = new Vector2(t.position.x, t.position.y);
currentSwipe = new Vector2(touchEnd.x - touchBegin.x, touchEnd.y - touchBegin.y);
currentSwipe.Normalize();
}
if (t.phase == TouchPhase.Ended) {
if (currentSwipe.y > 0 currentSwipe.x > -0.5f currentSwipe.x < 0.5f)
{
// jump
}
else if (currentSwipe.y < 0 currentSwipe.x > -0.5f currentSwipe.x < 0.5f)
{
// slide
}
}
}
}
else {
break;
}
}
If anyone could tell me the why my character doesn’t jump nor hide when I swipe I would be grateful.