I am new in Unity, and i want to add 8 different functions on 8 type of swipe on the screen by finger. I found the code for 4 swipes (left right up and down) but i want to add 8 swipes this shown in image (just for example) .
#pragma strict
private var fp : Vector2; // first finger position
private var lp : Vector2; // last finger position
function Update () {
for (var touch : Touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
fp = touch.position;
lp = touch.position;
}
if (touch.phase == TouchPhase.Moved )
{
lp = touch.position;
}
if(touch.phase == TouchPhase.Ended)
{
if((fp.x - lp.x) > 80) // left swipe
{
transform.Rotate(0,180,0);
}
else if((fp.x - lp.x) < -80) // right swipe
{
transform.Rotate(0,40,0);
}
else if((fp.y - lp.y) < -80 ) // up swipe
{
// add your jumping code here
}
else if((fp.y - lp.y) < 80 ) // down swipe
{
// add your slip code here
}
}
}
}