using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TouchTest : MonoBehaviour {
//手指一动的范围
private Vector2 _VerFingerMoveArea;
// 手指停留的时间
private float _FLStateTime;
//是否是首次触摸
private bool IsFirstTouch;
//屏显示
private string _StrTip;
//第一次触摸的时间
private float FlFirstTouchTime;
//第二次触摸的时间
private float SecondTouchTime;
void Start(){
}
void Update(){
//单个手指,第一个触摸的信息是移动话
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved) {
//得到手指x和y轴的增量d_
_VerFingerMoveArea.x += Input.GetTouch (0).deltaPosition.x;
_VerFingerMoveArea.y += Input.GetTouch (0).deltaPosition.y;
if (_VerFingerMoveArea.y > 100) {
_StrTip = "手指向上滑";
}
if (_VerFingerMoveArea.y < 100) {
_StrTip = "手指向下滑";
}
if (_VerFingerMoveArea.x > 100) {
_StrTip = "手指右滑动";
}
if (_VerFingerMoveArea.x < -100) {
_StrTip = "手指左滑动";
}
}
//当手指离开屏幕的时候,进行清零的操作
if (Input.GetTouch(0).phase == TouchPhase.Ended) {
_VerFingerMoveArea = Vector2.zero;
_FLStateTime = 0;
}
//手指停留
if (Input.GetTouch(0).phase == TouchPhase.Stationary) {
_FLStateTime += Input.GetTouch (0).deltaTime;
if (_FLStateTime > 0) {
_StrTip = "发现手指停留";
}
}
//手指双击
if (Input.GetTouch(0).phase == TouchPhase.Began) {
//如果是首次触摸,记录一下第二次触摸的时间
if (IsFirstTouch) {
SecondTouchTime = Time.deltaTime;
}
if (SecondTouchTime - FlFirstTouchTime >= 0.0f && SecondTouchTime- FlFirstTouchTime<= 0.2f) {
_StrTip = "发现手指触摸";
}
IsFirstTouch = true;
//记录第一次点击屏幕的时间
FlFirstTouchTime = Time.time;
}
}
void OnGUI(){
//将触摸的信息显示到手机端
GUILayout.Label (_StrTip);
}
}
手指触摸GetTouch
最新推荐文章于 2020-11-22 04:58:33 发布