Using Unityengine;
Using System.Collections;
public class Hide:monobehaviour
{
private bool Startposflag; Private Vector2 Startfingerpos;
Private Vector2 Nowfingerpos;
private float xmovedistance;
private float ymovedistance;
private int backvalue;
int Juduefinger ()
{
if (Input.touchcount > 0)
{
if (Input.gettouch (0). Phase = = Touchphase.began && Startposflag = = True)
{
Debug.Log ("====== begins to touch =====");
Startfingerpos = Input.gettouch (0). Position;
Startposflag = false;
}
if (Input.gettouch (0). Phase = = touchphase.ended)
{
Debug.Log ("====== release Touch =====");
Startposflag = true;
}
Nowfingerpos = Input.gettouch (0). Position;
Xmovedistance = Mathf.abs (nowfingerpos.x-startfingerpos.x);
Ymovedistance = Mathf.abs (NOWFINGERPOS.Y-STARTFINGERPOS.Y);
if (Xmovedistance > Ymovedistance)
{
if (nowfingerpos.x-startfingerpos.x > 0)
{
Debug.Log ("======= in negative direction along the X axis =====");
Backvalue =-1; Move along the x-axis in the negative direction
}
Else
{
Debug.Log ("======= moves ===== in the positive direction of the X-axis");
Backvalue = 1; Moving in the positive direction along the X axis
}
}
Else
{
if (Nowfingerpos.y-startfingerpos.y > 0)
{
Debug.Log ("======= moves ===== in the positive direction of the y-axis");
Backvalue = 1; Moving along the y-axis positive direction
}
Else
{
Debug.Log ("======= moves ===== in negative direction along the y axis");
Backvalue =-1; Move in negative direction along the Y axis
}
}
}
return backvalue;
}
The method of controlling the left and right slide is used to get the direction of the slide by the return value.
}
}