美文网首页
Unity-判断滑动屏幕触发事件

Unity-判断滑动屏幕触发事件

作者: 伊泽睿晨 | 来源:发表于2017-08-11 20:30 被阅读0次

判断滑动屏幕的方向,但是只能判断一次比较遗憾

参考官方API:http://docs.Unity3D.com/ScriptReference/EventType.html

代码:

private Vector2 lastPos;//上一个位置

private Vector2 currentPos;//现在的位置

private float timer;//时间计数器

private float offsetTime = 0.001f;//判断的时间间隔

voidOnGUI(){

if(Event.current.type == EventType.MouseDown) {//滑动开始

lastPos = Event.current.mousePosition;

currentPos = Event.current.mousePosition;

timer = 0;

}

if(Event.current.type == EventType.MouseDrag) {//滑动过程

currentPos = Event.current.mousePosition;

timer += Time.deltaTime;

if(timer > offsetTime) {

if(currentPos.x < lastPos.x) {

if(currentVector == slideVector.left) {

return;

}

currentVector = slideVector.left;

}

if(currentPos.x > lastPos.x) {

if(currentVector == slideVector.right) {

return;

}

currentVector = slideVector.right;

}

lastPos = currentPos;

timer = 0;

}

}

if(Event.current.type == EventType.MouseUp) {//滑动结束

currentVector = slideVector.nullVector;

}

}

相关文章

  • Unity-判断滑动屏幕触发事件

    判断滑动屏幕的方向,但是只能判断一次比较遗憾 参考官方API:http://docs.Unity3D.com/Sc...

  • JS事件

    一、四种touch触摸事件 事件 touchstart手指放在屏幕上时触发。 touchmove手指在屏幕滑动时持...

  • 浅谈touch事件

    触摸事件:用户手指放在屏幕上面的时候,在屏幕上滑动的时候或者是屏幕上移开的时候触发;主要的事件有:touchsta...

  • js触屏事件

    触屏事件,首先要有硬件支持,触屏设备 1.touchstart:手指按下屏幕触发 touchmove:手指滑动屏幕...

  • touchstart,touchmove判断手机中滑屏方向

    滑动屏幕 touchstart:接触屏幕时触发,touchmove:活动过程触发,touchend:离开屏幕时触...

  • touchstart,touchmove判断手机中滑屏方向

    滑动屏幕 touchstart:接触屏幕时触发,touchmove:活动过程触发,touchend:离开屏幕时触...

  • 移动端Touch事件

    touchstart: //手指放到屏幕上时触发touchmove: //手指在屏幕上滑动式触发touchend:...

  • 02-移动web开发

    一、移动端touch事件 当用户手指放在移动设备在屏幕上滑动会触发的touch事件 touch事件包含三个触摸列表...

  • 02-移动web开发

    一、移动端touch事件 当用户手指放在移动设备在屏幕上滑动会触发的touch事件 touch事件包含三个触摸列表...

  • touch事件

    touchstart: 手指放到屏幕上时触发 touchmove: 手指在屏幕上滑动式触发 touchend:手指...

网友评论

      本文标题:Unity-判断滑动屏幕触发事件

      本文链接:https://www.haomeiwen.com/subject/ksbrrxtx.html