前段时间开发的 iphone 项目,要实现一个功能,鼠标向右滑动时响应下一页事件,鼠标向
左滑动时响应上一页事件,现在把代码贴出来,用得着的可以看看。代码已加注释,不多解
释了。
private var first = Vector2.zero;
private var second = Vector2.zero;
function Update () {
}
function OnGUI () {
if(Event.current.type == EventType.MouseDown){//记录鼠标按下的位置
first = Event.current.mousePosition ;
}
if(Event.current.type == EventType.MouseDrag){//记录鼠标拖动的位置
second = Event.current.mousePosition ;
if(second.xfirst.x){//拖动的位置的 x 坐标比按下的位置的 x 坐标大时,响应向右事件
print("right");
}
first = second;
}
}
原文出处: http://prolove10.blog.163.com/blog/static/138411843201010184472690/?latestBlog