目标:判断滑动屏幕方向,只调用一次滑动事件处理函数
因为功能简单易懂,代码也比较简单,不再详细说明,参考官方API:http://docs.unity3d.com/ScriptReference/EventType.html
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
enum slideVector { nullVector, left, right };
private Vector2 lastPos;//上一个位置
private Vector2 currentPos;//下一个位置
private slideVector currentVector = slideVector.nullVector;//当前滑动方向
private float timer;//时间计数器
public float offsetTime = 0.01f;//判断的时间间隔
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
if (Event.current.type == EventType.MouseDown) {//滑动开始
lastPos = Event.current.mousePosition;
currentPos = Event.current.mousePosition;
timer = 0;
//TODO click event
Debug.Log ("Click begin && Drag begin");
}
if (Event.current.type =&