Touch left and right sliding events occur

Source: Internet
Author: User
Tags abs

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.
}




}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.