纳金网
标题:
判断鼠标向右或向左滑动,响应不同的事件
[打印本页]
作者:
王者再临
时间:
2014-8-31 22:59
标题:
判断鼠标向右或向左滑动,响应不同的事件
前段时间开发的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;
}
}
作者:
hyui
时间:
2014-9-1 04:42
感谢分享!
作者:
shenyg77
时间:
2014-9-3 11:19
好教材!!!!!!!
作者:
嵐淵瑟
时间:
2014-10-16 16:15
支持一個,感謝分享~~
欢迎光临 纳金网 (http://www.narkii.com/club/)
Powered by Discuz! X2.5