Unity3D判断鼠标向右或向左滑动,响应不同的事件

来源:互联网 发布:mysql官网下载tar.gz 编辑:程序博客网 时间:2024/06/04 18:21
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;     }   }

0 0
原创粉丝点击