- 最后登录
- 2016-8-29
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 23585
- 纳金币
- 20645
- 精华
- 62
|
前段时间开发的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.x<first.x){//拖动的位置的x坐标比按下的位置的x坐标小时,响应向左事件
print("left");
}
if(second.x>first.x){//拖动的位置的x坐标比按下的位置的x坐标大时,响应向右事件
print("right");
}
first = second;
}
}
|
|