prangya_p and kapilundan, Iām really sorry for not having responded for so long, I hadnāt visited the thread and I wasnāt notified that there were replies to it (maybe I could change this from my settings), I guess my answer is not so useful after 50 days but Iām posting it anyway as it could be useful to others at leastā¦
I use the following script, that is attached to my character (something like a chess pawn) and will move it on a board horizontally or vertically, depending on the swipes. The swipes can be made anywhere on the screen and you donāt have to make them on the character.
var comfortZoneVerticalSwipe: float = 50; // the vertical swipe will have to be inside a 50 pixels horizontal boundary
var comfortZoneHorizontalSwipe: float = 50; // the horizontal swipe will have to be inside a 50 pixels vertical boundary
var minSwipeDistance: float = 14; // the swipe distance will have to be longer than this for it to be considered a swipe
//the following 4 variables are used in some cases that I donāt want my character to be allowed to move on the board (itās a board game)
var allowGoUp: boolean = true;
var allowGoRight: boolean = true;
var allowGoLeft: boolean = true;
var allowGoDown: boolean = true;
function Update () {
if (Input.touchCount >0) {
var touch = Input.touches[0];
switch (touch.phase) { //following are 2 cases
case TouchPhase.Began: //here begins the 1st case
startPos = touch.position;
startTime = Time.time;
break; //here ends the 1st case
case TouchPhase.Ended: //here begins the 2nd case
var swipeTime = Time.time - startTime;
var swipeDist = (touch.position - startPos).magnitude;
var endPos = touch.position;
if ((Mathf.Abs(touch.position.x - startPos.x))<comfortZoneVerticalSwipe (swipeTime < maxSwipeTime) (swipeDist > minSwipeDistance) Mathf.Sign(touch.position.y - startPos.y)>0 !moving transform.position.z<3 allowGoUp)
{
//ā¦ then go up
moving=true;
[code here, to make character move the way you want (upwards)]
}
if ((Mathf.Abs(touch.position.x - startPos.x))<comfortZoneVerticalSwipe (swipeTime < maxSwipeTime) (swipeDist > minSwipeDistance) Mathf.Sign(touch.position.y - startPos.y)<0 !moving transform.position.z>-3 allowGoDown)
{
//ā¦ then go down
moving=true;
[code here, to make character move the way you want (downwards)]
}
if ((Mathf.Abs(touch.position.y - startPos.y))<comfortZoneHorizontalSwipe (swipeTime < maxSwipeTime) (swipeDist > minSwipeDistance) Mathf.Sign(touch.position.x - startPos.x)<0 !moving transform.position.x>-2 allowGoLeft)
{
//ā¦ then go left
moving=true;
[code here, to make character move the way you want (to the left)]
}
if ((Mathf.Abs(touch.position.y - startPos.y))<comfortZoneHorizontalSwipe (swipeTime < maxSwipeTime) (swipeDist > minSwipeDistance) Mathf.Sign(touch.position.x - startPos.x)>0 !moving transform.position.x<2 allowGoRight)
{
//ā¦then go right
moving=true;
[code here, to make character move the way you want (to the right)]
}
break; //here ends the 2nd case
}
}