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("======开始触摸=====");
startFingerPos = Input.GetTouch(0).position;
startPosFlag = false;
}
if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
//Debug.Log("======释放触摸=====");
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("=======沿着X轴负方向移动=====");
backValue = -1; //沿着X轴负方向移动
}
else
{
//Debug.Log("=======沿着X轴正方向移动=====");
backValue = 1; //沿着X轴正方向移动
}
}
else
{
if (nowFingerPos.y - startFingerPos.y > 0)
{
//Debug.Log("=======沿着Y轴正方向移动=====");
backValue = 1; //沿着Y轴正方向移动
}
else
{
//Debug.Log("=======沿着Y轴负方向移动=====");
backValue = -1; //沿着Y轴负方向移动
}
}
}
return backValue;
}
//控制左右滑动的方法,通过返回值来获取滑动的方向。
}
}