1、首先我们先定义一个枚举,用来表示手势滑动的四个方向:
<span style="font-size:14px;">public enum TouchDirection
{
Unkown,
Left,
Right,
Up,
Down
}</span>
2、定义类:TouchInput
<span style="font-size:14px;">public class TouchInput : MonoBehaviour {
public static TouchInput instance;
private Vector2 touchBeginPos;
private Vector2 touchEndPos;
}
</span>
3、对instance进行初始化:
<span style="font-size:14px;">void Start () {
Init();
}
void Init()
{
if (instance == null)
{
instance = this;
}
}</span>